Could you please let me know is there any way to replace multiple space with single space in java or spring? Any stringUtils function for same?
like
1.
test test
test test
2.
test test
test test
3.
test test
test test
Could you please let me know is there any way to replace multiple space with single space in java or spring? Any stringUtils function for same?
like
1.
test test
test test
2.
test test
test test
3.
test test
test test
To replace multiple spaces
output = input.replaceAll("[ ]+", " ");
Or replace multiple whitespace characters (including space, tab, new line, etc.)
output = input.replaceAll("\\s+", " ");
This is a variation of @p.s.w.g - it ignores newlines, but still get tabs and such.
output = input.replaceAll("[^\\S\\r\\n]+", " ");