How to remove last and first spaces from a string?

Possible duplicate:
How to trim a string in javascript?

I need to remove only from the last and first spaces from the common line.

Example:

var str = " hello world "; // become "hello world" var str = "ehi, do you come from ? "; // become "ehi, do you come from ?" var str = "I am from Cina"; // remain "I am from Cina" 

How can i do this?

+7
source share
1 answer

jQuery cropping is what you are looking for.

$.trim(' string with spaces at the ends ');

Or simple javascript:

' string with spaces at the ends '.trim()

+10
source

All Articles