Logo

Programming-Idioms

History of Idiom 219 > diff from v29 to v30

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

Version 29

2021-08-19, 08:13:32

Version 30

2021-08-19, 08:49:46

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, " +", " ")
Comments bubble
Replaces consecutive spaces with a single space.
Doc URL
https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions
Demo URL
https://sharplab.io/#gist:a54a6f9d0285c67d8e67af686a750c28