Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
102
rated 0 times [  108] [ 6]  / answers: 1 / hits: 57240  / 14 Years ago, fri, october 8, 2010, 12:00:00

How would I remove blank characters from a string in JavaScript?



A trim is very easy, but I don't know how to remove them from inside the string. For example:



222 334 -> 222334


More From » string

 Answers
6

Nick Craver has a good response, if you're OK with regex, go for it.



I just want to add that you can do this without Regex as well. You can just use a normal JavaScript replace(), using the parameters ( , ) to replace all whitespace with empty strings.



Update: Whoops, this won't work with multiple whitespaces.



JavaScript replace method on w3schools.


[#95376] Wednesday, October 6, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janjadonb

Total Points: 4
Total Questions: 114
Total Answers: 118

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
janjadonb questions
;