Looking for a one line C# code that would remove repeated chars from a string. Have done it with a simple loop with look-ahead but like to see a regex soln. Ex. input = "6200032111623451123345666" output = "623262345245"
Thanks.
Lyle
Looking for a one line C# code that would remove repeated chars from a string. Have done it with a simple loop with look-ahead but like to see a regex soln. Ex. input = "6200032111623451123345666" output = "623262345245"
Thanks.
Lyle
How about:
string s = Regex.Replace("6200032111623451123345666", @"(.)\1+", "");
The \1+
is "one or more" (greedy) of the back-reference to the first capture-group, .
(any character).