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+2 then
gotTopic=left(str,i-2)&"…"
exit for
else
gotTopic=str
end if
next
參考答案:Asc 函数
返回一个 Integer,代表字符串中首字母的字符代码。
语法
Asc(string)
必要的 string 参数可以是任何有效的字符串表达式。如果 string 中没有包含任何字符,则会产生运行时错误。
说明
在非 DBCS 系统下,返回值范围为 0 – 255 。在 DBCS 系统下,则为 -32768 – 32767。
注意 AscB 函数作用于包含在字符串中的字节数据,AscB 返回第一个字节的字符代码,而非字符的字符代码。AscW 函数返回 Unicode 字符代码,若平台不支持 Unicode,则与 Asc 函数功能相同。
Asc 函数示例
本示例使用 Asc 函数返回字符串首字母的字符值(ASCII 值)。
Dim MyNumber
MyNumber = Asc("A") ' 返回 65。
MyNumber = Asc("a") ' 返回 97。
MyNumber = Asc("Apple") ' 返回 65。