c#中如何判断字符串是汉字或是纯字母
有一段文字里面可能是汉字与字母的混合, 纯汉字, 纯字母, 如何判断这一段文字是不是纯字母? 如果可能的话如何从汉字与字母混合中过滤掉字母, 谢谢了 |
|
|
|
|
|
|
try...
C# code
-
Regex reg
=
new
Regex(
@"
[a-zA-Z]+
"
);
string
result
=
reg.Replace(yourStr,
""
); richTextBox2.Text
=
result;
|
|
|
|
|
|
|
引用 1 楼 lxcnn 的回复:
try...
C# codeRegex reg=new Regex(@"[a-zA-Z]+");string result= reg.Replace(yourStr,"");
richTextBox2.Text= result;
|
|
|
|
|
|
|
string s="123工要234"; byte[] bytes=System.Text.Encoding.Default.GetBytes(s); if (bytes.Length > s.Length) { MessageBox.Show("字符串中有中文字符") } |
|
|
|
|
|
|
引用 1 楼 lxcnn 的回复:
try...
C# codeRegex reg=new Regex(@"[a-zA-Z]+");string result= reg.Replace(yourStr,"");
richTextBox2.Text= result;
|
|
|
|
|
|
|
string regexstr = @"^[A-Za-z]+$"; System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(regexstr, System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Match m = regex.Match(""); if(m.Success) { } |
|
|
|
|
|
|
可以使用Char.IsLetter()来判断是否是字母 |
|
|
|
|
|
|
字母的ASCII都大于0 如果有负的ASCII就说明是汉字 |
|
转载于:https://www.cnblogs.com/kevinzhwl/archive/2010/06/29/3878918.html