String Trimming
Downloadable Files
string_trimming1.htm ( 2,894 Bytes )
This demonstrates how to strip the white space from the left, right, or both ends of a string. The trimming is done using a regular expression that seeks out space characters. For some reason, I could not get the special space characters "\s" to work; however, other white-space characters (ex. "\t", "\r", "\n") seem to work just fine.
NOTE: As of May 3, 2006, I realized why I could not get the "\s" space character to work. And hence, I have changed the uploaded file... but the description above remains the same.
If you were going to be using trimming in an application, you might want to make "trim()" a prototype function of the standard String object.
Added April 17, 2006 / Updated May 3, 2006



