How to remove non-alphabets from a String

This post is all about how to remove all characters that are not alphabets from a String. For the reverse of the same, refer here. For eg, if you want to only "ABC" from "A1@348474B*&C" then the following snippet of code would be fine in Java.

String test = "A1@348474B*&C";
test = test.replaceAll("[a-zA-Z]",""); //This will replace all non alpha characters
System.out.println("The extracted String is "+test);

The output of the above code will be,

The extracted String is ABC

Hope this was helpful to you in someway. Happy Working...


Popular posts from this blog

Changing Timezone in Postgresql, Ubuntu

Display Logic and read only logic In Openbravo

Dissecting Openbravo 3.0 UI Architecture