JS removal string Chinese and white space we can use the substitution and regular expression to implement, the following is sorted out two simple examples, I hope to be useful to you.
1. Remove Space:
function Movespace () {
var str= "ABC Defg";
Alert (str.replace (/[]/g, ""));
}
Movespace ();
2. Remove Chinese:
var title = "String Zifuchuan"
var reg=/[u4e00-u9fa5]/g;
var result=title.replace (Reg, "");
alert (result);
3. Remove the space at both ends of the string
String.prototype.trim=function () {return this.replace (^/s*) | ( /s*$)/g, ');
. Remove all spaces from the string:
String.prototype.sTrim = function () {return this.replace (//s/g, ');}
Or:
var s = "ASD ddd bbb SSS";
var reg =//s/g;
var ss = S.replace (Reg, "");
Alert (ss);
< script language= "JavaScript" >
String.prototype.trim=function () {
Return This.replace (/(^s*) | ( s*$)/g, "");
}
String.prototype.ltrim=function () {
Return This.replace (/(^s*)/g, "");
}
String.prototype.rtrim=function () {
Return This.replace (/(s*$)/g, "");
}
</script>
If you also want to remove other characters, you can write the same implementation.