Home > DeveloperSection > Forums > How to remove special characters from an string?
Ashish Pandey

Total Post:128

Points:898
Posted on    October-04-2013 9:15 AM

 Java Java 
Ratings:


 2 Reply(s)
 743  View(s)
Rate this:

I want to remove special character like:

- + ^ . : ,

from a string using java.



jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    October-04-2013 9:28 AM

Post is removed by the User.

jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    October-04-2013 9:29 AM

Try replaceAll() method of the String class.

BTW here is the method, return type and parameters.

public String replaceAll(String regex, String replacement)

Example:

String str = "Hello +-^ my + - friends ^ ^^-- ^^^ +!";
str = str.replaceAll("[-+^]*", "");

It should remove all the {'^', '+', '-'} chars that you wanted to remove!


Don't want to miss updates? Please click the below button!

Follow MindStick