A few days ago, I encountered a problem and it took me a long time to solve it. I was so angry! Putting a string into setTimeout cannot execute the method. Later, I found out that there is an additional line break at the string, so I can't find it without looking carefully. Just use regular expressions to remove line breaks.
//Remove spaces String.prototype.Trim = function() {return this.replace(//s+/g, "");}//Remove line break function ClearBr(key) {key = key.replace(/<//?.+?>/g,"");key = key.replace(/[/r/n]/g, "");return key;}//Remove spaces on the left function LTrim(str) {return str.replace(/^/s*/g,"");}//Remove right space function RTrim(str) {return str.replace(//s*$/g,"");}//Remove the spaces at both ends of the string function trim(str) {return str.replace(/(^/s*)|(/s*$)/g, "");}//Remove the middle spaces of the string function CTim(str) {return str.replace(//s/g,'');}//Is it a string composed of numbers function is_digitals(str) {var reg=/^[0-9]*$/; //Match the integer return reg.test(str);}}//Is it a string composed of numbers function is_digitals(str) {var reg=/^[0-9]*$/; //Match the integer return reg.test(str);}Now I find that I like to use regular expressions more and more, haha! It is relatively simple and intuitive. Of course, the first question is that you can be familiar with regular expressions. I am also trying to write this JS method to delete newlines by myself, and it really made me realize it!
The above JS regular expression (recommended) for removing spaces and line breaks is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.