For example, I want to convert the string test123 test124 test125
to
test123+""+test124+""+test125
or test123test开发者_如何学C124test125
.
How to achieve this?
Thanks
String output = inputText.replaceAll("\\s+","");
use String.replace()
:
"test123 test124 test125".replace(" ", "");
Use String result = yourString.replace(" ","");
You can use the replace method of the string like
str.replace(" ","");
You can also try using String Tokeniser, simplest way is,
String s = "test123 test124 test125";
StringTokenizer st = new StringTokenizer( s, " " );
while(st.hasMoreTokens())
{
System.out.print(st.nextToken());
}
精彩评论