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

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

问,有什么办法得到"你a"为三个字符。
...全文
114 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mqflf 2003-12-13
  • 打赏
  • 举报
回复
谢谢
答案已找到,用了asc(string)>0类似的方法,

rongwenfeng 2003-12-12
  • 打赏
  • 举报
回复
var nLength = 0 ;
var strChar = null ;
var strEsc = null ;
for( var nCnt = 0; nCnt < this.length; nCnt++ )
{
strChar = this.charAt( nCnt ) ;
strEsc = escape( strChar ) ;
if( strEsc.length >= 4)
{
nCharCode = parseInt( strEsc.substr( 2, 4 ), 16 ) ;
if( 0xFF61 > nCharCode || nCharCode > 0xFF9F )
{
nLength++ ;
}
}
nLength++ ;
}
return nLength ;
flyingding 2003-12-12
  • 打赏
  • 举报
回复
//不好意思,上面的最后忘了返回数值了
<script language="vbs">
function getWidth(str)
width=0
for i=0 to len(str)
s=mid(str,i,1)
if(asc(s)>0)then
width=width+1
else
width=width+2
end if
next
getWidth=width
end function
</script>
flyingding 2003-12-12
  • 打赏
  • 举报
回复
<script language="vbs">
function getWidth(str)
width=0
for i=0 to len(str)
s=mid(str,i,1)
if(asc(s)>0)then
width=width+1
else
width=width+2
end if
next
end function
</script>
qwater 2003-12-12
  • 打赏
  • 举报
回复
up
dgseamaple 2003-12-12
  • 打赏
  • 举报
回复
关注ing.......
angelheavens 2003-12-12
  • 打赏
  • 举报
回复
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
Primer2002cn 2003-12-12
  • 打赏
  • 举报
回复
关注
  • 打赏
  • 举报
回复
<SCRIPT language=JavaScript>
// 获取字符串的长度
function checkStrLen(value){
var str,Num = 0;
for (var i=0;i<value.length;i++){
str = value.substring(i,i+1);
if (str<="~") //判断是否双字节
Num+=1;
else
Num+=2;
}
return Num;
return value.length;
}
</script>

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧