当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

使用ASP截取含有汉字的字符串

减小字体 增大字体 作者:佚名  来源:翔宇亭IT乐园  发布时间:2019-1-3 0:44:40

:2010-04-01 13:36:00

如何实现ASP截取字符串时,把汉字作为两个字符呢?本文就给出了相应的源代码:

rem 显示左边的n个字符(自动识别汉字)
Function LeftTrue(str,n)
         If len(str)<=n/2 Then
             LeftTrue=str
         Else
             l=len(str)
             t=l
             TStr=""
             t=0
             for i=1 to l 
                 c=asc(mid(str,i,1)) 
                 If c<0 then c=c+65536
                 If c>255 then 
                        t=t+2 
                 Else 
                        t=t+1
                 End If 
                 If t>n Then exit for 
                 TStr=TStr&(mid(str,i,1)) 
             next
             LeftTrue = TStr 
        End If
End Function

上边在截取汉字时,利用了一个函数,在使用时,直接调用此函数就行了。


使用ASP截取含有汉字的字符串