How can I remove extra white space in a string in JavaScript?

前端 未结 9 1014
故里飘歌
故里飘歌 2021-02-09 01:47

How can I remove extra white space (i.e. more than one white space character in a row) from text in JavaScript?

E.g

match    the start using.

9条回答
  •  滥情空心
    2021-02-09 02:14

    myString = Regex.Replace(myString, @"\s+", " "); 
    

    or even:

    RegexOptions options = RegexOptions.None;
    Regex regex = new Regex(@"[ ]{2,}", options);     
    tempo = regex.Replace(tempo, @" ");
    

提交回复
热议问题