連続する複数の半角スペースをひとつにする方法
文書番号:20450
文字列の中に連続する複数のスペースがある場合に、その連続するスペースをひとつにする方法です。
【文字列中の連続した複数のスペースをひとつにする】
Dim s As String = "りんご みかん ばなな"
Dim reg As New System.Text.RegularExpressions.Regex("(\s)\1{1,}")
'連続する複数のスペースをひとつにする
s = reg.Replace(s, " ")
Dim s As String = "りんご みかん ばなな"
Dim reg As New System.Text.RegularExpressions.Regex("(\s)\1{1,}")
'全角スペースを半角に置き換え
s = s.Replace(" "," ")
'連続する複数のスペースをひとつにする
s = reg.Replace(s, " ")