[Javascript] How do I refer to whitespace characters?

Dan Costea costea.dan at ssi-schaefer.ro
Fri Apr 26 12:52:22 CDT 2002


You can use a RegExp (regular expression) like this /\s+/. This will do.

Example:

var s = "             asdf'  sadfAS  ";
alert ("->" + s + "<-\n->" + s.replace (/\s+/, "") + "<-");


Dan.



----- Original Message ----- 
From: "Lau" <lau at goldenweb.com.au>
To: <javascript at LaTech.edu>
Sent: Thursday, April 25, 2002 10:02 PM
Subject: [Javascript] How do I refer to whitespace characters?


> I want to read a string and remove all the whitespace before a word.
> How do I refer to tabs and newline characters etc.
> Can anyone give me a full list of what I should be checking for? 
> 
> 
> while(mystr.length>0 && mystr.charAt(0)==" ") 
>      mystr= mystr.substr(1);
> 
> 
> Peace
> Lau
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list