|          
对中英文字符串的长度的一点小解(jaklin 2000.8.9)
 
 常常有人问到中英文字符串的长度和判断问题, 因为在ASP和SQL7中英文也只占用一个字节。其实是很简单, 只是麻烦一点而已。
 一般来说对于中文和英文最大的区别在于它们的ASCII码不同, 因此可以通过它们的ASCII码来判别是不是英文, 并求出字符串的长度。中文的ASCII码值一般大于255。下面的函数是用于求中英文字符串的长度。
 
 function strlen(str)
 dim p_len
 p_len=0
 strlen=0
 iftrim(str)<>"" then
 p_len=len(trim(str))
 for i=1 to p_len
 ifasc(mid(str,i,1))>255 then
 strlen=int(strlen) + 2
 else
 strlen=int(strlen) + 1
 end if
 next
 end if
 end function
 |