This article mainly introduces some javascript Functions implemented by String. prototype in detail. If you need them, please refer to them and hope to help you.
The Code is as follows:
// String. prototype
// Batch replace, such as 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 C = C. replace (A [I], B [I]);
};
Return C;
};
// Remove the white spaces at both ends of the character
String. prototype. Trim = function (){
Return this. replace (/(^ [/t/n/r] *) | ([/t/n/r] * $)/g ,'');
};
// Remove the white space on the left of the character
String. prototype. LTrim = function (){
Return this. replace (/^ [/t/n/r]/g ,'');
};
// Remove the white space on the right of the character
String. prototype. RTrim = function (){
Return this. replace (/[/t/n/r] * $/g ,'');
};
// Returns the length of two characters in a Chinese character.
String. prototype. ChineseLength = function ()
{
Return this. replace (/[^/x00-/xff]/g, "**"). length;
};
// Determine whether the 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) = );
};
// Determine whether the string starts with the specified string
String. prototype. StartsWith = function (str)
{
Return this. substr (0, str. length) = str;
};
// Where does the string start?
String. prototype. Remove = function (A, B ){
Var s = '';
If (A> 0) s = this. substring (0, );
If (A + B Return s;
};