Alex Rivera | Logout

Replace all whitespace characters

Asked 2011-06-28T13:17:14.943
176

I want to replace all occurrences of white space characters (space, tab, newline) in JavaScript.
How to do so?

I tried:

str.replace(/ /gi, "X")
Edit
Report

1 Answer

5

Try this:

str.replace(/\s/g, "X")
answered 2011-06-28T13:19:38.543

Your Answer