admin类[jscript]

类别:Asp 点击:0 评论:0 推荐:

<input value="看看superDullWolf的CNWord类引用实例,vbs,改进了一下,可以提供chinese出现的位置了" id="input1" style="width:100%"/>
<br/>
<button onclick="vbs:classAndRegExp">验证</button>
<script language = "vbscript">
sub classAndRegExp()
set wolf = new CNWord
wolf.str = input1.value
 
msgbox "含有中文数" & wolf.CNcount
msgbox "含有中文块数" & wolf.CNBlockCount
msgbox "第2个中文块是--->" &  wolf.CN(2)
msgbox "第1个中文块出现的位置是--->" &  wolf.CNIndex(1)
set wolf = nothing
end sub
</script>


<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
dim Match
 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  CNIndex(x)
dim Arr()
dim maxBound : maxBound = CNBlockCount
redim Arr(maxBound)
dim i:i=1
dim Match
 For each Match  in regEx.Execute(str)
Arr(i) =  Match.FirstIndex + 1 
i = i + 1
 next
 if x<=maxBound then CNIndex = 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
</script>

本文地址:http://com.8s8s.com/it/it7930.htm