samedi 23 janvier 2016

Replacing multiple char from String with single space

I want to replace multiple character in given string with a single space.

eg: He is a very very good boy, isn't he? Should be replaced to

He is a very very good boy isn t he

String str = "He is a very very good boy, isn't he?"
String str2 = str.replaceAll("![,?.\_'@+] +"," ");
 String []tokens = str2.split(" +");

for(int i = 0; i< tokens.length; i++)
       System.out.println(tokens[i]);

But the output is

He is a very very good boy, isn't he?

Please correct my code if possible or suggest a new one.

Aucun commentaire:

Enregistrer un commentaire