Logo

Programming-Idioms

History of Idiom 219 > diff from v30 to v31

Edit summary for version 31 by zqwnvl:
New VB implementation by user [zqwnvl]

Version 30

2021-08-19, 08:49:46

Version 31

2021-08-19, 08:51:47

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Extra Keywords
collapse repeated
Extra Keywords
collapse repeated
Imports
Imports System.Text.RegularExpressions
Code
Dim t As String = Regex.Replace(s, "\s+", " ")
Comments bubble
Replaces consecutive whitespace with a space.
Doc URL
https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions
Demo URL
http://sharplab.io/#gist:4be2f23b5660adc65dc80b6be6385b08