One simple way of trimming a string is to make use of a powerful regular expression?as opposed to iterating and removing the space characters one by one. To see how this works, save the code below as an .htm file, and then load the file into IE. Click in the text field and then tab out of it to see the code in action.
<html> Trim String