求中英文混合字符串宽度值。

在vbScript中有什么办法可以得到中英文混排字符患的字符宽度值,
比如字符"你"占二个字符,而英文"a"只占一个字符宽,

问,有什么办法得到"你a"为三个字符。
---------------------------------------------------------------

function strLength(str)
ON ERROR RESUME NEXT
dim WINNT_CHINESE
WINNT_CHINESE = (len("论坛")=2)
if WINNT_CHINESE then
dim l,t,c
dim i
l=len(str)
t=l
for i=1 to l
c=asc(mid(str,i,1))
if c<0 then c=c+65536
if c>255 then
t=t+1
end if
next
strLength=t
else
strLength=len(str)
end if
if err.number<>0 then err.clear
end function
---------------------------------------------------------------

 1<script language="vbs">   
 2function getWidth(str)   
 3width=0   
 4for i=0 to len(str)   
 5s=mid(str,i,1)   
 6if(asc(s)>0)then   
 7width=width+1   
 8else   
 9width=width+2   
10end if   
11next   
12getWidth = width   
13end function   
14</script>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus