1)函数:rowscode()-----每行显示n个字母,自动换行
Function rowscode(str,n)
If len(str)<=n/2 Then
rowscode=str
Else
Dim TStr
Dim l,t,c
Dim i
l=len(str)
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
TStr=TStr&(mid(str,i,1))
If t>n Then
TStr=TStr&"<br>"
t=0
End if
next
rowscode= TStr
End If
End Function
2)函数:lefttrue()-----如果字符串str的长度大于n,则显示左边的n个字符
Function LeftTrue(str,n)
If len(str)<=n/2 Then
LeftTrue=str
Else
Dim TStr
Dim l,t,c
Dim i
l=len(str)
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
博客介绍了C语言中两个字符串处理函数。rowscode函数可每行显示n个字母并自动换行,通过遍历字符串,根据字符编码判断长度,超过n则换行;lefttrue函数在字符串长度大于n时,显示左边n个字符,超出部分用省略号表示。
705

被折叠的 条评论
为什么被折叠?



