Difference between revisions of "Remove non-letters from a string"

From CodeCodex

m
Line 4: Line 4:
 
This code removes common symbols and numbers from a string, returning letters only.  (Note, not all symbols are included.)
 
This code removes common symbols and numbers from a string, returning letters only.  (Note, not all symbols are included.)
 
  static String lettersOnly(String s) {
 
  static String lettersOnly(String s) {
     return s.replaceAll("[A-Z]|[a-z]|[ !@#\\$%\\^&\\*\\(\\)_\\+\\-={}\\|:\"<>\\?\\-=\\[\\];',\\./`~'£€¥]","");
+
     return s.replaceAll("[0-9]|[ !@#\\$%\\^&\\*\\(\\)_\\+\\-={}\\|:\"<>\\?\\-=\\[\\];',\\./`~'£€¥]","");
 
  }
 
  }
  
 
[[Category:Java]]
 
[[Category:Java]]
 
[[Category:String]]
 
[[Category:String]]

Revision as of 21:40, 29 November 2006

Related content:

Implementations

Java

This code removes common symbols and numbers from a string, returning letters only. (Note, not all symbols are included.)

static String lettersOnly(String s) {
   return s.replaceAll("[0-9]|[ !@#\\$%\\^&\\*\\(\\)_\\+\\-={}\\|:\"<>\\?\\-=\\[\\];',\\./`~'£€¥]","");
}