JS Remove the space instance trim (), LTrim (), RTrim () need friends can come to the reference, I hope to help you
1, JS Remove the string of space//to the left space; function LTrim (s) ... {return S.replace (/(^s*)/g, "");} Go to the right space; function RTrim (s) ... {return S.replace (/(s*$)/g, "");} Go to the left and right space; function trim (s) ... {//s.replace (^s*) | ( s*$)/g, ""); return RTrim (LTrim (s)); 2. Functions//parameters for removing spaces on both sides of the string: MyStr incoming string//return: string mystr function Trim (mystr) {while (Mystr.indexof (") ==0) && (mystr.l ength>1)) {mystr=mystr.substring (1,mystr.length);} Remove the front space while ((Mystr.lastindexof ("") ==mystr.length-1) && (mystr.length>1)) {mystr=mystr.substring (0, MYSTR.LENGTH-1); }//Remove the trailing space if (mystr== "") {mystr= "";} return mystr; }