信息发布→ 登录 注册 退出

ASP 支持中文的len(),left(),right()的函数代码

发布时间:2026-01-11

点击量:
比如一个汉字也只会算一个字节,在排版时如果全是汉字,好说,反正没什么差别,但是如果被操作的字符串有汉字又有英文字母时,就不方便了,以下三个函数可以代替ASP自带的相关函数。

  也有注意的地方,如果用在循环中,因不变量“i”也是常用于循环的变量,执行以下函数时,“i”的值会发生变化,如果是调用他的循环中用到相同的变量,会产生未知的结果,请换用其它变量名。

以下用法和len(),left(),right()一样。

程序代码
复制代码 代码如下:
Function Strlength(Str)
Temp_Str=Len(Str)
For I=1 To Temp_Str
Test_Str=(Mid(Str,I,1))
If Asc(Test_Str)>0 Then
Strlength=Strlength+1
Else
Strlength=Strlength+2
End If
Next
End Function

Function Strleft(Str,L)
Temp_Str=Len(Str)
For I=1 To Temp_Str
Test_Str=(Mid(Str,I,1))
Strleft=Strleft&Test_Str
If Asc(Test_Str)>0 Then
lens=lens+1
Else
lens=lens+2
End If
If lens>=L Then Exit For
Next
End Function

Function Strright(Str,L)
Temp_Str=Len(Str)
For i = Temp_Str to 1 step -1
Test_Str=(Mid(Str,I,1))
Strright=Test_Str&Strright
If Asc(Test_Str)>0 Then
lens=lens+1
Else
lens=lens+2
End If
If lens>=L Then Exit For
Next
End Function
标签:# 英文字母  # ASP  # BR  # left  # len  # 被操  # 变量名  # 换用  # 没什么  # 便了  # 中文  # 用在  # 自带  # 只会  # 又有  # 就不  # 也有  # asp 字符串截取函数  # 字符串截取  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!