Click to See Complete Forum and Search --> : Replacing a space character


nickcrispini
10-16-2003, 05:27 PM
I want to replace a space character with no space. So if I had two words such as 'Hello World' I would it to be replaced with 'HelloWorld'.

Is this possible with JavaScript?

Thanks.

Nick

pyro
10-16-2003, 06:06 PM
Try this:

<script type="text/javascript">
str = "Hello World";
str = str.replace(/\s/g, "");
alert (str);
</script>\s will replace any Unicode whitespace character. If you only want to remove spaces, just replace the \s with an actual space.