1. Chinese-English mixed character interception
//Chinese length interception calculation, it is advisable to mix in English, the number up rounding, accuracy of 1 English characters error, an English is a character, a Chinese character counted as a char. //Sub ("Chinese Zlsd", 1), "Medium" //Sub ("Chinese Zlsd", 3), "Chinese" functionSubch (str,n) {varr=/[^\x00-\xff]/G; if(Str.replace (R, "MM"). Length<=n) {returnstr;} varM=math.floor (N/2); for(vari=m;i<str.length;i++){ if(Str.substr (0,i). Replace (R, "MM"). length>=N) { returnSTR.SUBSTR (0, i); } } returnstr; }
2. Remove spaces before and after characters
Remove space before and after string
function () { returnthis. replace (/^\s*/, ""). Replace (/\s*$/, "");
3. Get string lengths in English and Chinese
// get a Chinese-English string length, one for one, one for English function getstrlength (str) { var cArr = Str.match (/[^\x00-\xff]/ig); return null ? 0 : carr.length); }
4. Get url parameter length
// url parameter get function (parm) { varnew RegExp ("(^|&)" + parm + "= ([^&]*] (&|$)"); var this. substr (this. indexOf ("\?") +1). Match (reg); if (r!=nullreturnreturnnull;
String length calculation, interception, URL parameter acquisition