我这里使用的是Linq,如果你不会,那就使用循环吧。 var strAbc = (from p in str where (p>='a'&&p<='z')||(p>='A'&&p<='Z') select p); System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (var item in strAbc) { sb.Append(item.ToString()); } return sb.ToString();
晚街
2024-05-16 01:20:52
英文的正则 [a-zA-Z]
口拙嘴笨
2024-05-16 03:15:59
string str = "wefwef中ewfw国abwefc"; char[] cr = str.ToCharArray(); StringBuilder strbuilder = new StringBuilder(); foreach (char aa in cr) { if ((aa >= 'a' && aa <= 'z') || ((aa >= 'A' && aa <= 'Z'))) { strbuilder.Append(aa); } }
雨薇之恋
2024-05-16 07:12:02
var str=Regex.Replace("wefwef中ewfw国abwefc", "[a-z]", "", RegexOptions.IgnoreCase);