Copy Code code as follows:
String.prototype use
Batch substitution, for example: Str. ReplaceAll ([/a/g,/b/g,/c/g],["AAA", "BBB", "CCC"])
String.prototype.replaceall=function (a,b) {
var c=this;
for (Var i=0;i<a.length;i++) {
C=c.replace (A[i],b[i]);
};
return C;
};
Remove whitespace characters at both ends of a character
String.prototype.trim=function () {
Return This.replace (/(^[/t/n/r]*) | ( [/t/n/r]*$)/g, ');
};
Remove the white space character to the left of the character
String.prototype.ltrim=function () {
Return This.replace (/^[/t/n/r]/g, "");
};
Remove the white space character to the right of the character
String.prototype.rtrim=function () {
Return This.replace (/[/t/n/r]*$/g, "");
};
Returns the length of the character, one in Chinese 2
String.prototype.chineselength=function ()
{
Return This.replace (/[^/x00-/xff]/g, "* *"). Length;
};
Determines whether a string ends with the specified string
String.prototype.endswith=function (a,b) {
var c=this.length;
var d=a.length;
if (d>c) return false;
if (B) {
var e=new RegExp (A + ' $ ', ' I ');
Return E.test (this);
}else Return (d==0| | This.substr (c-d,d) ==a);
};
Determines whether a string starts with the specified string
String.prototype.StartsWith = function (str)
{
Return this.substr (0, str.length) = = str;
};
How long does the string start from?
String.prototype.remove=function (a,b) {
var s= ';
if (a>0) s=this.substring (0,a);
if (a+b<this.length) s+=this.substring (a+b,this.length);
return s;
};