JScript "trim" function

Results 1 to 2 of 2

Thread: JScript "trim" function

  1. #1
    Dan Nye Guest

    Default JScript "trim" function

    Just starting out trying out ASP in JScript, and read Richard Lowe&#039s "Server-Side JScript Objects" document, which was a great help to me.<BR><BR>However, I couldn&#039t get his jsTrim function to work. No matter what, it wouldn&#039t strip the whitespace from the end of a string (I copied & pasted it directly, and tried numerous things).<BR><BR>For anyone else that&#039s having the same problem, here&#039s one I came up with (sorry if it&#039s bad - my RegExp knowledge is very very very limited :o):<BR><BR>function jsTrim(strInput) { return(strInput.replace(/^s+/, "").replace(/s+$/, "")); }<BR><BR>Hope this helps!<BR><BR>Keep up the good work with JScript/ASP forum!<BR><BR>Dan<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: JScript

    function trim(txt) { // trim leading and trailing spaces<BR> while (txt.substring(0,1) == &#039 &#039) {<BR> txt = txt.substring(1, txt.length);<BR> }<BR> while (txt.substring(txt.length-1,txt.length) == &#039 &#039) {<BR> txt = txt.substring(0, txt.length-1);<BR> } return txt;<BR>} <BR><BR>better compatibility, and simpler to understand than regex<BR><BR>j

Posting Permissions

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