zoukankan      html  css  js  c++  java
  • ASP如何限定中英文混合的文字输出字数?

     1<%
     2' 字符串截取函数,用于信息标题 
     3' strWord需要截取的字符串 
     4' intByteLength显示的字节长度,1个汉字两个字节 
     5' intPadDotAmount背截取后尾部补充点的个数 
     6' 字符串截取函数,用于信息标题 
     7Function FixString(ByVal strWord, ByVal intByteLength, ByVal intPadDotAmount) 
     8        If strWord > "" Then 
     9                If Length(strWord) <= intByteLength Then 
    10                        FixString = strWord 
    11                Else 
    12                        Dim i 
    13                        Dim intLength 
    14                        Dim strChar 
    15                        Dim bytChar 
    16                        intLength = 0 
    17                        For i = 1 to Len(strWord) 
    18                                strChar = Mid(strWord, i, 1
    19                                bytChar = Asc(Mid(strWord, i, 1)) 
    20                                If bytChar < 0 or bytChar > 255 Then 
    21                                        intLength = intLength + 2 
    22                                Else 
    23                                        intLength = intLength + 1 
    24                                End If 
    25                                If intLength > intByteLength Then Exit For 
    26                                FixString = FixString & strChar 
    27                        Next 
    28                        FixString = FixString & String(intPadDotAmount, "."
    29                End If 
    30        Else 
    31                FixString = "" 
    32        End If 
    33End Function
     
    34' 计算字符串长度,1个汉字为两个字节 
    35Function Length(ByVal strWord) 
    36        If strWord > "" Then 
    37                Dim i, bytChar 
    38                Length = 0 
    39                For i = 1 to Len(strWord) 
    40                        bytChar = Asc(Mid(strWord, i, 1)) 
    41                        If bytChar < 0 or bytChar > 255 Then Length = Length + 2 Else Length = Length + 1 
    42                Next 
    43        Else 
    44                Length = -1 
    45        End If 
    46End Function

    47content= FixString("测试,.ba我实,<>",10,0)
    48response.Write(content)
    49%>
  • 相关阅读:
    ORACLE删除当前用户下所有的表的方法
    解决Tomcat对POST请求文件上传大小的限制
    Windows下如何查看某个端口被谁占用
    javamail彻底解决中文乱码的方法
    Tomcat通过setenv.bat指定jdk和jre(相对路径)
    Linux nohup命令详解
    shell 重启java 程序
    jstack命令执行报错:Unable to open socket file: target process not responding or HotSpot VM not loaded
    ToStringBuilder.reflectionToString用法
    vue自定义指令+只能输入数字和英文+修改v-model绑定的值
  • 原文地址:https://www.cnblogs.com/zwl12549/p/853221.html
Copyright © 2011-2022 走看看