Solved

Regular expressions

Posted on 2004-09-27
6
284 Views
Last Modified: 2010-04-23
Is it possible in VB.Net to write  a regular expression that will replace any character that appears more than once consecutively with just one of that character?

For example 'sssdftrgggh' -> 'sdftrgh' or 11125644766 -> 1256476

Thanks,

Tommy
0
Comment
Question by:TommyV10
6 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12159707
I don't know about a regular expression but this should do the same

Public Function removedbl(ByVal s As String) As String
        Dim returnstring As String
        Dim x As String = ""
        For y As Integer = 0 To s.Length - 1
            If Not s.Substring(y, 1) = x Then
                returnstring += s.Substring(y, 1)
                x = s.Substring(y, 1)
            End If
        Next
        Return (returnstring)
    End Function
0
 

Expert Comment

by:bradtm
ID: 12161996
Here is a resource of hundreds of already made regexpressions.

http://regexlib.com/DisplayPatterns.aspx
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 12170693
([\w])\1

Bob
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 1

Author Comment

by:TommyV10
ID: 12177176
Thanks Bob, that sort of works but it only seems to perfrom the replace if an odd number of characters are encountered.  It will replace 'a' or 'aaa' to 'a' but leaves out 'aa' or 'aaaa'
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12178742
Yeah, I noticed that too.  You could try a While...End While loop, until their are no more matches.

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12183039
([\w])\1+

Bob
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now