C # Validation Chinese

Source: Internet
Author: User

There are many ways to verify Chinese in C #, here are a few of them for reference, and the validation of regular expressions is not written here, there is a chance to make it up later.

Method One:

Private BOOLIschina (stringmsg) {    stringtemp;  for(inti =0; I < Msg. Length; i++) {Temp= Msg. Substring (I,1); byte[] Ser = encoding.getencoding ("gb2312").        GetBytes (temp); if(Ser. Length = =2)        {            return true; }    }    return false;}

Method Two:

Private BOOLCheckchina (stringinput) {    intCode =0; intChfrom = Convert.ToInt32 ("4e00", -);//Range (0X4E00~0X9FFF) converted to int (chfrom~chend)    intChend = Convert.ToInt32 ("9fff", -);  for(inti =0; I < input. Length; i++) {Code= CHAR.CONVERTTOUTF32 (Input,1);//gets the character Unicode encoding at the index specified in string input        if(Code >= chfrom && Code <=chend) {            return true;//when code returns true within the Chinese range        }    }    return false;}

Method Three:

 Public BOOLISCHINA1 (stringCString) {    BOOLBoolvalue =false;  for(inti =0; i < cstring.length; i++)    {        if(Convert.ToInt32 (Convert.tochar (cstring.substring (i,1))) <convert.toint32 (Convert.tochar ( -)) {boolvalue=false; }        Else        {            returnBoolvalue =true; }    }    returnBoolvalue;}

C # Validation Chinese

Related Article

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.