Dave's Brain

Browse - Programming Tips - How can I "trim" (remove whitespace characters from the start and end)

Date: 2011feb14
Language: javaScript

Q.  How can I "trim" (remove whitespace characters from the start and end)
a string with javaScript that works in all browsers?

A.  Firefox has a trim() but IE doesn't so nice solution is to use trim()
in jQuery like this:

str = $.trim(str);
This alone isn't reason enough to use jQuery in a project. Its pretty easy to write a trim using regular expressions.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.