Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trimming spaces 1

Status
Not open for further replies.

Simonwat

Programmer
Nov 29, 2000
2
CA
Hi,
In Javascript, Is there a way to trim all the left and right spaces in a string like Trim() function in asp?
Thanks
Simon
 
function String_rtrim()//returns string without right whitespace
{var xi = /\s*$/;var bx=this.replace(xi,"");return bx}
String.prototype.rtrim=String_rtrim;String.prototype.chomp=String_rtrim;

function String_ltrim()//returns string without left whitespace
{var xi = /^\s*/;var bx=this.replace(xi,"");return bx}
String.prototype.ltrim=String_ltrim;

function String_trim()//returns string without lead or trail spc
{var xi = this.rtrim();var bx=xi.ltrim();return bx}
String.prototype.trim=String_trim;

now just call somestring.trim() to return a string w/o leading or trailing space jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top