jquery - How to remove spaces from a string using JavaScript? -
how remove spaces in string? instance:
input : '/var/www/site/brand new document.docx'
output : '/var/www/site/brandnewdocument.docx'
thanks
this?
str = str.replace(/\s/g, ''); example
var str = '/var/www/site/brand new document.docx'; document.write( str.replace(/\s/g, '') ); update: based on this question, this:
str = str.replace(/\s+/g, ''); is better solution. produces same result, faster.
the regex
\s regex "whitespace", , g "global" flag, meaning match \s (whitespaces).
a great explanation + can found here.
as side note, replace content between single quotes want, can replace whitespace other string.
Comments
Post a Comment