samedi 1 août 2015

Not able to remove multiple whitespace(s) in a string in java

Problem: Can't remove multiple white spaces in a string while working in eclipse editor

Context:

String myString1 ="aye  bye  tye  ";
String myString2 =myString1.replaceAll("\\s+","");
System.out.println("replaced string ="+myString2);

In the output the white spaces are not removed and the result is the same as the string,

replaced string =aye  bye  tye

is getting printed

But if there is only one white space between the words like,

String myString1 ="aye bye tye";

the result is correctly coming as below:

replaced string =ayebyetye

I wonder where I am going wrong?

Aucun commentaire:

Enregistrer un commentaire