Trim string using javascript No ratings yet.

By | June 19, 2016

You can do this using various techniques. Some of them are as follows:

Method 1: Using Plain Javascript:

You can do it using the simple simple Javascript expression as follows:

Output:

 

Method two: Using trim() function of Jquery:

In order to trim a string, firstly you can use the $.trim() function of Jquery to make the input string neat(removes all newlines, spaces and tabs from the beginning and end of the supplied string).

Since you would be using the $.trim() function of Jquery, don’t forgot to include the library file of Jquery:

And here is a simple solution to this task :

Output:

 

And if you want to truncate a string to nearest white space using javascript, you can refer this article :

Truncating string to nearest white space using Javascript .

 

Likes(2)Dislikes(0)

Please rate this

2 thoughts on “Trim string using javascript

  1. coupons

    Den Gutschein koennte ich gut gebrauchen, um eine neue Brille zu kaufen und den FIlm dann auch in scharf sehen zu koennen.
    coupons http://zophim.me/user/savingplaza3/

    Likes(0)Dislikes(0)
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *