如何使用javascript从字符串中删除所有空格。 我有这样this--使用javascript删除空格
var Title = "";
var Str="g g";
Title = Str.replace(/^\s+|\s+$/g, '');
this gives me result Title=g g
how to get result Title=gg
如何使用javascript从字符串中删除所有空格。 我有这样this--使用javascript删除空格
var Title = "";
var Str="g g";
Title = Str.replace(/^\s+|\s+$/g, '');
this gives me result Title=g g
how to get result Title=gg
使用正则表达式如下代码:
Str.replace(/\s+/g, '');
你现在所拥有的该一个刚刚从strippes开始或您的字符串的结尾空格。
试试这个
Title = Str.replace(/ /g, '');
更改代码:
var title = Str.replace(/\s+/g, '');
你原来的正则表达式将只从字符串开始处或结束修整空间。
你可以使用:
var Str="g g";
Str.replace(" ", "");
其工作的感谢 –