Javascript method to trim a string

Results 1 to 3 of 3

Thread: Javascript method to trim a string

  1. #1
    Tim Westmoreland Guest

    Default Javascript method to trim a string

    Is there a JavaScript method/function that will trim the spaces from a string?

  2. #2
    Joseph Hatcher Guest

    Default RE: Javascript method to trim a string

    Try something like this....<BR><BR><BR>function LTrim(phrase)<BR>{<BR> while (phrase.charAt(0)==" ")<BR> {<BR> phrase=phrase.substr(1,phrase.length-1)<BR> }<BR>return(phrase)<BR>}<BR><BR><BR>function RTrim(phrase)<BR>{<BR> <BR> while (phrase.charAt(phrase.length-1)==" ")<BR> {<BR> phrase=phrase.substr(0,phrase.length-2)<BR> }<BR>return(phrase)<BR>}<BR><BR><BR>function Trim(phrase)<BR>{<BR> phrase=LTrim(phrase)<BR> phrase=RTrim(phrase)<BR> <BR> return(phrase)<BR>}<BR><BR><BR><BR>

  3. #3
    Tim Westmoreland Guest

    Default RE: Javascript method to trim a string

    Cool, it works great. Thanx.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •