Replace all whitespace characters
How to do so?
str.replace(/ /gi, “X”)
Matches a single white space
character, including space, tab, form
feed, line feed.
str = str.replace(/\s/g, "X");
\s is a meta character that covers all white space. You don’t need to make it case-insensitive — white space doesn’t have case.
We can also use this if we want to change all multiple joined blank spaces with a single character:
Have you tried the
EDIT (correct version without typo):
Actually it has been worked but
just try this.
take the value /\s/g into a string variable like
String a = /\s/g; str = str.replaceAll(a,"X");