当前位置:编程学习 > asp >>

判断一个字符串里面包含有中文或者英文

答案:<script language="vbscript">
class CNWord

public str

private sub Class_Initialize()
set regEx =new RegExp
regEx.IgnoreCase = True '设置是否区分大小写。
regEx.Global = True '设置全局可用性。
end sub

private regEx


Property get CN(x)
dim Arr()
dim maxBound : maxBound = CNBlockCount
redim Arr(maxBound)
dim i:i=1
For each Match in regEx.Execute(str)
Arr(i) = Match
i = i + 1
next
if x<=maxBound then CN = Arr(x)
End Property



Property get CNcount
'返回含有中文的字数
regEx.Pattern = "[\u4e00-\u9fa5]"
CNcount = findCHNnum()
End Property

Property get CNBlockCount
'返回含有中文的块数
regEx.Pattern = "[\u4e00-\u9fa5]+"
CNBlockCount = findCHNnum()
End Property


private function findCHNnum()
findCHNnum = regEx.Execute(str).count
end function




private sub Class_Terminate()
set regEx = nothing
end sub

end class

set ccc= new CNWord
ccc.str ="CNWord类引用实例,vbs"

msgbox "含有中文数" & ccc.CNcount
msgbox "含有中文块数" & ccc.CNBlockCount
msgbox "第2个中文块是--->" & ccc.CN(2)

set ccc = nothing
</script>


上一个:在DataGrid里面添加Label后,如何给Label赋值
下一个:获得数据库的空间大小,已使用的数据库空间大小

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,