Determines whether a string contains Chinese characters and returns the Chinese character position.

Source: Internet
Author: User

{

Judge whether a string contains Chinese Characters
// Judgestr: string to be judged
// Posint: the first Chinese character position
}

Function tform1.ishavechinese (judgestr: string; var posint: integer): Boolean;
VaR
P: pwidechar; // the character to be judged
Count: integer; // The position containing Chinese characters.
Ishave: Boolean; // whether the returned value contains Chinese Characters
Begin

Ishave: = false; // whether the returned value contains Chinese characters. The default value is false.
Count: = 1; // the default position containing Chinese characters is 1.

P: = pwidechar (judgestr); // converts the string to be judged.

// Judge each character cyclically
While P ^ <> #0 do
Begin
Case P ^
#$4e00 .. # $9fa5:
Begin
Ishave: = true; // set whether to include Chinese characters and return true
Posint: = count; // you can specify a position that contains Chinese characters.
Break; // exit the loop
End;

End;

INC (P );
INC (count); // The position containing Chinese characters increases progressively
End;

Result: = ishave;
End;

--- Restore content end ---

Determines whether a string contains Chinese characters and returns the Chinese character position.

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.