Home >Web Front-end >JS Tutorial >How to remove the carriage return character in javascript
In JavaScript, you can use the replace() function with the regular expression "/[\r\n]/g" to remove the carriage return. The syntax format is "Str.replace(/[\r\n]/g" , "")". The replace() method is used to replace the substring matching the regular expression with some characters in the string.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Removing carriage returns in javascript
In javascript, you can use the replace() method with regular expressions to remove spaces, carriage returns, and line feeds, which is very efficient.
Thereplace() method is used to replace some characters with other characters in a string, or replace a substring that matches a regular expression.
Example:
function iGetInnerText(testStr) { var resultStr = testStr.replace(/\ +/g, ""); //去掉空格 resultStr = testStr.replace(/[ ]/g, ""); //去掉空格 resultStr = testStr.replace(/[\r\n]/g, ""); //去掉回车换行 return resultStr; } var testStr="sssss vvvvv"; var result=iGetInnerText(testStr);
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to remove the carriage return character in javascript. For more information, please follow other related articles on the PHP Chinese website!