'获得字符串长度
以下是代码片段: function byteLen(str)'获取字符串实际占用字节数 dim lenStr lenStr=0 lenTemp=len(str) dim strTemp for i=1 to lenTemp strTemp=ascw(mid(str,i,1)) if strTemp>255 or strTemp<=0 then lenStr=lenStr+2 else lenStr=lenStr+1 end if next byteLen=lenStr end function |
'截取字符长度 飞飞Asp技@术乐园
以下是代码片段: Function cutStr(str,strlen) dim l,t,c l=len(str) t=0 for i=1 to l c=Abs(Ascw(Mid(str,i,1))) if c>255 then t=t+2 else t=t+1 end if if t>=strlen then cutStr=left(str,i) exit for else cutStr=str end if next cutStr=replace(cutStr,chr(10),"") end Function | 飞飞Asp技术乐.园
例如
以下是代码片段: str1="我不知道你要做什么" str2="2007我不知道你要做什么" response.Write(cutStr(str1,6)&" ") '我不知 response.Write(cutStr(str2,6)) '2007我 |
Sql 自定义函数版本
以下是代码片段: CREATE FUNCTION lenb(@textstr varchar(50)) RETURNS int AS BEGIN declare @lenstr int select @lenstr=0 declare @lentemp int select @lentemp=len(@textstr) declare @strtemp int declare @i int select @i=1 --declare @back int --set @back=0 while @i<=@lentemp begin set @strTemp=unicode(substring(@textstr, @i,1)) if @strtemp>255 or @strtemp<=0 set @lenstr=@lenstr+2 else set @lenstr=@lenstr+1 set @i=@i+1 end return @lenstr END | 飞飞A,sp技术乐园
|