ASP中计算中英文字符串的长度
根据汉字的ASC码值都是大于255的特点,很容易就可以写出一个计算实际长度的函数来啦~
<%
Function CheckStringLength(txt)
txt=trim(txt)
x = len(txt)
y = 0
for ii = 1 to x
if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then
’ 如果是中文
y = y + 2
else
y = y + 1
end if
next
CheckStringLength = y
End Function
response.Write(CheckStringLength("fsdfs地在在dfsdf"))
%>
日期:2008-1-3 阅读统计:读取中.. 来自:网络 作者:
最新评论 - 查看全部评论
- · 暂时没有评论!
发表评论
