Domino Code Fragment

Code Name*
Trim function
Date*
11/04/1999
Source (or email address if you prefer)*
Daryl Rochette
IP address:.3.17.6.75
Description*
Simulates @Trim in JavaScript
Type*
JavaScript
Categories*
(Misc)
Implementation:
None (plug and play)
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code: //This function accepts a string value, oldTerm, and removes leading & trailing spaces, //and replaces multi-spaces with a single space character. function trim(oldTerm) { var work = oldTerm; //Remove any leading spaces... while (work.substring(0,1) == " ") { work = work.substring(1,work.length); } //Remove any trailing spaces while (work.substring(work.length-1,work.length) == " ") { work = work.substring(0,work.length-1); } //Replace all double spaces with a single space, continue until no more double spaces. while (work.indexOf(" ",0) != -1) { var ind = work.indexOf(" ") work = work.substring(0,ind) + work.substring(ind+1,work.length); } return work; }