求一个字符串函数

tmpx 2006-01-09 10:34:29
问题:
输入一个字符串,自动识别字符和汉字,1个汉字算2个字符,求出字符串的长度
...全文
78 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
竹林听雨2005 2006-01-09
  • 打赏
  • 举报
回复
这个东西不错,呵。收藏。
KimSoft 2006-01-09
  • 打赏
  • 举报
回复
你要的是第一个函数
KimSoft 2006-01-09
  • 打赏
  • 举报
回复
'------------------------------------------------------------
' 作用:让Len,Left,Right函数识别中文
' 对中文识别为两个字符,ASCII码为一个
' 可用此函数代替Len,Left,Right函数
'------------------------------------------------------------

Function StrLen(Str)
strTemp = Len(Str)
For I = 1 To strTemp
strTest = (Mid(Str, I, 1))
If Asc(strTest) > 0 Then
StrLen = StrLen + 1
Else
StrLen = StrLen + 2
End If
Next
End Function

Function StrLeft(Str, L)
strTemp = Len(Str)
For I = 1 To strTemp
strTest = (Mid(Str, I, 1))
StrLeft = StrLeft & strTest
If Asc(strTest) > 0 Then
Lens = Lens + 1
Else
Lens = Lens + 2
End If
If Lens >= L Then Exit For
Next
End Function

Function StrRight(Str, L)
strTemp = Len(Str)
For I = strTemp To 1 Step -1
strTest = (Mid(Str, I, 1))
StrRight = strTest & StrRight
If Asc(strTest) > 0 Then
Lens = Lens + 1
Else
Lens = Lens + 2
End If
If Lens >= L Then Exit For
Next
End Function

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧