Regex squash

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jim_adams@hotmail.com

    #1

    Regex squash

    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

  • Dragon

    #2
    Re: Regex squash

    Probably that's what you want:

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

    HTH,
    Roman

    <jim_adams@hotm ail.com> ???????/???????? ? ???????? ?????????:
    news:1147275517 .879711.300760@ j73g2000cwa.goo glegroups.com.. .[color=blue]
    > I'd like to use regex to replace a specified character that repeats[/color]
    two[color=blue]
    > or more times with one instance of that character.
    >
    > For example,
    >
    > mystring = "a.....b"
    >
    > regex squash (mystring, ".") -> "a.b"
    >
    > Thanks for your help.
    >
    > -Jim
    >[/color]


    Comment

    Working...