[Turn] c # to determine whether there are letters in the string and the replacement examples of characters in the string

First, we need to add a reference 
to the namespace " using System.Text.RegularExpressions;" 
 Let's take a string as an example: the 
 
  
 
code is as follows: 
string ss = " aaZ31 dd2f3 " ;
 string sss = ss.Replace ( "  " , "" ); // Remove the spaces in the string ss 
  
 
string sss2 = Regex.Replace (ss, " [a-zA-Z] " , "" ); // Remove the English letters in the string ss 
 
MessageBox.Show (sss) ; // The dialog pop-up value is aaZ31dd2f3 
MessageBox.Show (sss2); // The dialog pop-up value is 31 23 
 
if (Regex.Matches (ss, " [a-zA-Z] ") .Count> 0 ) // If the number of captured letters is greater than zero 
 
{ 
 
      // there are English letters in the string 
 
} 
 
else 
 
       // vice versa

 

Guess you like

Origin www.cnblogs.com/cyqdeshenluo/p/12742535.html