初音游戏手机版:[新手问题] 帮我理解一下这两段代码的意思?

来源:百度文库 编辑:中科新闻网 时间:2024/05/03 02:44:50
function gotTopic(str,strlen)
dim l,t,c, i
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))

if c>255 then
t=t+2
else
t=t+1
end if

if t>=strlen then
gotTopic=left(str,i)&"..."
exit for
else
gotTopic=str
end if
next
end function

gotTopic(str,strlen) 应该是截取str长度的函数。

若 str 长度>strlen 则 gotTopic返回值就等于原 str 左边 strlen 个字符 加上 .... ,
否则 gotTopic返回值就等于字符串 str.

-------------------------
c=Abs(Asc(Mid(str,i,1)))

if c>255 then
t=t+2
else
t=t+1
end if
上面代码中:
Mid(str,i,1)是获取字符串 str 的第i个字符。

若字符串 str 的第i个字符的Asc码的绝对值大于 255。
则标始该字符长度为2。
可能就是处理双字节的情况。