How does javascript replace multiple spaces in a string with a single space
This article mainly explains "javascript how to replace multiple spaces in a string with a single space". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how javascript replaces multiple spaces in a string with a single space.
Javascript reduces multiple spaces in a string to a single space code instance:
In practical applications, there may be a requirement to reduce multiple spaces in a string to a single space.
The following is an example of a code that can achieve this function.
The code is as follows:
/ / A pair of string extensions String.prototype.ResetBlank=function () {var regEx = /\ sencoding length g; return this.replace (regEx,'');}; var str= "jb51.net is a good site"; console.log (str.length); console.log (str.ResetBlank ().
Ordinary ones can be done through the following code
Str=str.replace (/\ s+/ig, "")
The above code meets our requirements, and you can read more about it.
At this point, I believe you have a deeper understanding of "javascript how to replace multiple spaces in a string with a single space". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!