Home > Article > Web Front-end > How to remove whitespace characters from string
This article mainly introduces how to delete blank characters in strings. I hope you can learn patiently.
replace regular matching method is as follows:
Remove all spaces in the string: str = str.replace(/\s*/g,"" );
Remove spaces at both ends of the string: str = str.replace(/^\s*|\s*$/g,"");
Remove the spaces on the left side of the string: str = str.replace(/^\s*/,"");
Remove the spaces on the right side of the string Spaces on the side: str = str.replace(/(\s*$)/g,"");
1."/ /" This is a fixed writing method,
2. "\s" is a transfer symbol used to match any whitespace character, including spaces, tabs, form feeds, etc.,
3. "g" means that global matching will replace All matching substrings, if "g" is not added, will end after matching the first one .
Related recommendations:
JS implementation loads js and css files when needed_html/css_WEB-ITnose
An example of interaction between php and js
The above is the detailed content of How to remove whitespace characters from string. For more information, please follow other related articles on the PHP Chinese website!