Quantcast
Channel: TechiePark » Jsp
Viewing all articles
Browse latest Browse all 10

How to remove white-space from a String

$
0
0
/*** replace multiple whitespaces between words with single blank */ String before=" hi how are you "; String value = before.trim().replaceAll("[ ][ ]*", " "); or String value = before.replaceAll("\\b\\s{2,}\\b", " "); //before : hi how are you //after: hi how are you /* remove leading whitespace */ String value= before.replaceAll("^\\s+", ""); //before : hi [...]

Viewing all articles
Browse latest Browse all 10

Trending Articles