x Hint: Register, if you want to hide ads.
x Did you like it? Well, then please consider making a donation :)

How do I replace multiple spaces with a single space?

Replace multiple spaces example

Tags: #digits, #example, #numbers, #remove, #replace, #simple, #space, #string. Views: 1538. stackoverflow, 7/12/2015
Link 1: http://www.systemtextregularexpressions.com/r14/how-do-i-replace-multiple-spaces-with-a-single-space
Link 2: http://www.systemtextregularexpressions.com/r14 (short)


Length: 0b, Line: 1, Cursor: 0

RegexOptions

IsMatch=true

Result

1 2 3 4 5 6 7 8 9

Share (without adding to database):

Source code

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
//.NET Regex.Replace Online Tester: www.systemtextregularexpressions.com

//Namespace
using System.Text.RegularExpressions;

//Regex Pattern
string pattern = @"\s+";

//Regex example #1
Regex r = new Regex(@"\s+");
string result1 = r.Replace("input text", "replacement text");

//Regex example #2
string result2 = Regex.Replace("input text", @"\s+", "replacement text");
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
'.NET Regex.Replace Online Tester: www.systemtextregularexpressions.com

'Namespace
Imports System.Text.RegularExpressions

'Regex Pattern
Dim pattern As String = "\s+"

'Regex example #1
Dim r As Regex = New Regex("\s+")
Dim result1 As String = r.Replace("input text", "replacement text")

'Regex example #2
Dim result2 As String = Regex.Replace("input text", "\s+", "replacement text")