Replace special characters in a String using java


package in.javatutorials;

/**
* @author javatutorials
* @since version 1.0
*
* Below class replaces the special characters in a string with empty value
*
*/
public class ReplaceSpecialCharacters {

public static final String REG_EXPR = “[!\”#$%&'()*+-./:;<=>?@\\^_{|}~`,.\\[\\]]*”;

/**
* @param args
*/
public static void main(String[] args){
String str = “a – b +c^d!e+f g . h (Pvt) Ltd.”;
//Create class object and call replace special characters method
ReplaceSpecialCharacters rsc = new ReplaceSpecialCharacters();
String afterReplacing = rsc.replaceSpecialChars(str);
System.out.println(“After replacing special characters : “+afterReplacing);
}

/**
* @param string String
* @return string String
*/
public String replaceSpecialChars(String string){
string = string.replaceAll(REG_EXPR, “”);
while(string.indexOf(” “) != -1){
string = string.replaceAll(” “, ” “);
}

return string;
}

}

Advertisements
About

I born in Good cultural place called India. My family is traditional family. We fallow all Indian traditions.

Tagged with: , , , , , , , , ,
Posted in JAVA
4 comments on “Replace special characters in a String using java
  1. […] Replace special characters in a String using java. […]

  2. […] Replace special characters in a String using java […]

  3. […] Replace special characters in a String using java […]

  4. […] Replace special characters in a String using java […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 678 other followers

Calendar
January 2013
M T W T F S S
« Dec   Feb »
 123456
78910111213
14151617181920
21222324252627
28293031  
Mallikarjun Gunda

This is Mallikarjun Gunda, I am working as a software professional. Blogging is my Passion. This blog contains the posts on Java related technologies and programming languages. I am happy to share my knowledge through the blogs.

Blog Stats
  • 262,784 hits
IndiBlogger
malliktalksjava.wordpress.c...
70/100