VB6 checks whether a string contains Chinese Characters

Source: Internet
Author: User

For Google and csdn, there is no correct and rigorous VB6 to determine whether the string contains Chinese characters, or simply to determine whether the ASC () return value is less than 0 (this can only determine whether it is a double byte string, such as Korean, Japanese, Chinese, and Arabic. It cannot be determined as Chinese. It is not rigorous to judge Chinese characters.
It is better to give a more rigorous method to determine whether or not it contains Chinese characters. I hope someone will find it later and it will be helpful.
Create a form, put a button, default name, and paste the following code on the code page.

Private sub commandemediclick () <br/> dim S1, S2, S3, s4 as string <br/> S1 = "Chinese" <br/> S2 = "Hangzhou" <br/> S3 = "English" <br/> S4 = "123" <br/> dim result as string <br/> result = "+ S1 +" + IIF (includechinese (S1 ), "include Chinese characters", "do not include Chinese characters") <br/> result = Result + vbcrlf + "+ S2 +" + IIF (includechinese (S2 ), "include Chinese characters", "do not include Chinese characters") <br/> result = Result + vbcrlf + "+ S3 +" + IIF (includechinese (S3), "including Chinese characters", "not including Chinese characters ") <br/> result = Result + vbcrlf + "+ S4 +" + IIF (includechinese (S4), "contains Chinese characters", "does not contain Chinese characters ") <br/> msgbox result <br/> end sub </P> <p> 'determines whether the string contains Chinese characters. <br/> Public Function includechinese (byval s as string) as Boolean <br/> 'defines the byte array to point to the string <br/> dim data () as byte <br/> DATA = S <br/>' temporary variable, the integer length is 2, which is used to determine whether it is a Chinese character, because the Chinese character is dubyte <br/> dim t as integer <br/> 'defines the cyclic variable <br/> dim I as integer <Br/> 'boundary value of Chinese characters <br/> 'Because writing directly & h9fa5 is considered as a negative integer, it must be written as a string for conversion. <br/> dim LB, UB as long <br/> lB = clng ("& h4e00") 'minimum Chinese character value <br/> UB = clng ("& h9fa5") <br/> 'cyclically judge, the range of Chinese characters is 4e00 ~ 9fa5 <br/> 'because I do not understand VB6 skills, I use a complicated method for type conversion. <br/> for I = 0 to ubound (data) step 2 <br/> T = clng ("& H" + hex (data (I) + data (I + 1) * 255 )) 'concatenate two consecutive bytes into an integer <br/> If T> = LB and T <= UB then <br/> specify dechinese = true'. True is returned if any Chinese character is found. <br/> exit function <br/> end if <br/> next <br/> includechinese = false' does not contain Chinese characters <br/> end function <br/>

 

Output result:

"Chinese" contains Chinese Characters
"Category" does not contain Chinese Characters
"English" does not contain Chinese Characters
"123" does not contain Chinese Characters

 

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.