JQuery: utility functions II – trimming strings

Published Fri, Aug 7 2009 14:21

In this post we’re going to talk about the helper trim method. This is really a simple function which removes any leading or trailing whitespaces from the passed string. Notice that the method uses regular expressions and considers white spaces as any char that matches spaces, form feed, new line, return, tab and vertical tab characters.

Using the function is really simple, as  you can see from this snippet:

var someText = "    Hello there";
alert("-" + $.trim(someText) + "-");

And that’s it. Keep tuned for more on JQuery.

Filed under:

Comments

# 9eFish said on Sunday, August 09, 2009 8:42 AM

9efish.感谢你的文章 - Trackback from 9eFish

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above:  

Search

This Blog

Tags

Community

Archives

Syndication

Email Notifications

News




  • View Luis Abreu's profile on LinkedIn


    Follow me at Twitter

    My books

    Silverlight 4.0: Curso Completo

    ASP.NET 4.0: Curso Completo

    Portuguese LINQ book cover

    Portuguese ASP.NET 3.5 book cover

    Portuguese ASP.NET AJAX book cover

    Portuguese ASP.NET AJAX book cover