To determine if a string contains either Chinese or English

Source: Internet
Author: User
Chinese | string <script language= "VBScript" >
Class Cnword

Public Str

Private Sub Class_Initialize ()
Set RegEx =new REGEXP
Regex.ignorecase = True ' Sets whether case sensitive.
Regex.global = True ' Sets global availability.
End Sub

Private RegEx


Property Get CN (x)
Dim Arr ()
Dim Maxbound:maxbound = Cnblockcount
ReDim ARR (Maxbound)
Dim I:i=1
For the Match in Regex.execute (str)
ARR (i) = Match
i = i + 1
Next
If X<=maxbound then CN = ARR (x)
End Property



Property Get Cncount
' Returns the number of words containing Chinese
Regex.pattern = "[\u4e00-\u9fa5]"
Cncount = Findchnnum ()
End Property

Property Get Cnblockcount
' Returns the number of blocks containing Chinese
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 class reference instance, VBS"

MsgBox "Contains Chinese number" & CCC. Cncount
MsgBox "Contains Chinese block number" & CCC. Cnblockcount
MsgBox "2nd Chinese block is--->" & CCC. CN (2)

Set CCC = Nothing
</script>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.