Home All Groups Group Topic Archive Search About
Author
10 May 2006 3:38 PM
jim_adams
I'd like to use regex to replace a specified character that repeats two
or more times with one instance of that character.

For example,

mystring = "a.....b"

regex squash (mystring, ".") -> "a.b"

Thanks for your help.

-Jim

Author
11 May 2006 2:45 PM
Dragon
Probably that's what you want:

~
    Function Squash(ByVal input As String, ByVal character As Char) As
String
        Return Regex.Replace(input, Regex.Escape(character) & "+",
character)
    End Function
~

HTH,
Roman

<jim_ad***@hotmail.com> ???????/???????? ? ???????? ?????????:
Show quoteHide quote
news:1147275517.879711.300760@j73g2000cwa.googlegroups.com...
> I'd like to use regex to replace a specified character that repeats
two
> or more times with one instance of that character.
>
> For example,
>
> mystring = "a.....b"
>
> regex squash (mystring, ".") -> "a.b"
>
> Thanks for your help.
>
> -Jim
>