^ [\ U4e00-\ u9fa5] {} $ this is a regular expression used to verify Chinese Characters
System. Text. encoding. Default. getbytecount (strstring); -- returns the number of bytes.
// Determine whether the string is a number.
String str1 = This. textbox1.text. Trim ();
If (RegEx. ismatch (str1, @ "^ \ D + $ "))
{
MessageBox. Show ("yes."); // yes;
}
Else
MessageBox. Show ("not a number ");
Return;
//
// Using system. Text. regularexpressions;
String STR = "23sd SDF 95 columns gfwef 56 countries anywhere Ge ga 4 ";
Matchcollection MS = RegEx. Matches (STR, "[\ u4e00-\ u9fa5]");
String SSS = NULL;
For (INT I = 0; I <Ms. Count; I ++)
{
SSS + = MS [I]. value;
}
MessageBox. Show (SSS );
If (RegEx. ismatch (STR, "[0-9]") // number
MessageBox. Show ("the string contains numbers ");
If (RegEx. ismatch (STR, "[A-Z]") // lowercase letter
MessageBox. Show ("the string contains lowercase letters ");
If (RegEx. ismatch (STR, "[A-Z]") // uppercase letter
MessageBox. Show ("the string contains lowercase letters ");
If (RegEx. ismatch (STR, "[A-Za-Z]") // all letters
MessageBox. Show ("the string contains letters ");
If (RegEx. ismatch (STR, "[\ u4e00-\ u9fa5]") // Chinese Character
MessageBox. Show ("the string contains Chinese characters ");
}
If (islength (textbox. Text, 100) = false) // exceeds 100 words
Public bool islength (string STR, int maxlength)
{
Char C;
Int intlength = 0;
For (INT I = 0; I <Str. length; I ++)
{
C = STR [I];
If (C <128) | (C> 160) & (c <224) | (C> 65376) & (c <65439 )))
{
Intlength ++;
}
Else
{
Intlength + = 2;
}
}
If (intlength> maxlength)
{
Return false;
}
Return true;
}