我只需要从通用字符串中删除最后一个和第一个空格。
示例:
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"
我该怎么做?
答案 0 :(得分:17)
trim from jQuery正是您要找的。 p>
$.trim(' string with spaces at the ends ');
或普通的javascript:
' string with spaces at the ends '.trim()