8

JavaScript のテキストから余分な空白文字 (行に複数の空白文字) を削除するにはどうすればよいですか?

例えば

match    the start using.

"match" と "the" の間のスペースを 1 つを除いてすべて削除するにはどうすればよいですか?

4

9 に答える 9

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

あるいは:

RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@"[ ]{2,}", options);     
tempo = regex.Replace(tempo, @" ");
于 2013-10-03T09:34:10.517 に答える
1

ただやって、

var str = "match    the start using. Remove the extra space between match and the";
str = str.replace( /\s\s+/g, ' ' );
于 2013-10-03T09:32:47.170 に答える
1
  function RemoveExtraSpace(value)
  {
    return value.replace(/\s+/g,' ');
  }
于 2013-10-03T09:33:26.080 に答える
0

確かに、正規表現を使用して:

var str = "match    the start using. Remove the extra space between match and the";
str = str.replace(/\s/g, ' ')
于 2013-10-03T09:32:50.220 に答える