HOW TO REMOVE SPECIAL CHARACTERS FROM AN STRING?

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
Java 
 1040  View(s)
Ratings:
Rate this:

I want to remove special character like:

- + ^ . : ,

from a string using java.

  1. jacob rasel

    Post:88

    Points:616
    Re: How to remove special characters from an string?

    Post is removed by the User.

  1. jacob rasel

    Post:88

    Points:616
    Re: How to remove special characters from an string?

    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!

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!