If your project is using the JQuery framework, you will of course Choose: Jquery.trim (String) to remove the null characters from the end of the string. If you don't use jquery as a simple implementation. I have previously sent a small snippet of code: JavaScript to remove the string around the space-trim (), this write is relatively rough and to use the recursive operation. So many people are very dissatisfied with the quality of the code, including me.
Occasionally looked down the jquery code and found the very value of our learning.
See how it achieves this function, the code has only one sentence: Use the regular method.
JavaScript Trim Implementation Code
function Trim (text) {
Return (text | | ""). Replace (/^/s+|/s+$/g, "");
}
If you don't use jquery or other frameworks in your project, you can copy the code with this feature. believe that the structure and quality of the code will be another you satisfied.