明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

判斷一個(gè)字符串里面包含有中文或者英文

[摘要]<script language="vbscript"> class CNWord public str private sub Class_Initialize() set regEx =new RegExp regEx.IgnoreCase = True ...

<script language="vbscript">
class CNWord

public str

private sub Class_Initialize()
set regEx =new RegExp
regEx.IgnoreCase = True '設(shè)置是否區(qū)分大小寫(xiě)。
regEx.Global = True '設(shè)置全局可用性。
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
'返回含有中文的字?jǐn)?shù)
regEx.Pattern = "[\u4e00-\u9fa5]"
CNcount = findCHNnum()
End Property

Property get CNBlockCount
'返回含有中文的塊數(shù)
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類(lèi)引用實(shí)例,vbs"

msgbox "含有中文數(shù)" & ccc.CNcount
msgbox "含有中文塊數(shù)" & ccc.CNBlockCount
msgbox "第2個(gè)中文塊是--->" & ccc.CN(2)

set ccc = nothing
</script>