This line:
Regex regex = new Regex(@"[ ]{2,}", options);
Creates a regular expression object, that will look for occurrences of 2 or more adjacent spaces. The [ ]
creates a character group that contains a space - it could have been written as a
, but would then be less readable is my guess. The {2,}
means 2 or more (unbounded) of the previous character (or character group).
See this handy RegEx cheat sheet for .NET regex syntax.
This line finds all such occurrences and replaces them with one space:
string outStr = regex.Replace(inStr, @" ");
The replace function finds all matches of the regex in the first string parameter, and replaces them with the second string.
In both cases, there is no need for a verbatim string literal (starting with @
).