Solved

Update Regx expression and Function

Posted on 2007-03-21
3
164 Views
Last Modified: 2010-04-23
VB.NET 2003
REGEX AND  Function need Updating:


I'am having problems with the following function below...
It is taking  normal 2 numerator and 2 denominator fractions and parsing them apart...


It should do the following:


11/2   1 1/2
11/4   1 1/4
11/8   1 1/8
21/2   2 1/2
21/4   2 1/4
21/8   2 1/8
31/2   3 1/2
31/4   3 1/4
31/8   3 1/8

or



11/16   1 1/16
21/64   2 1/64
21/32   2 1/32


it needs to leave alone double numerator and denominator
13/64
11/16
etc....


An assumption is a <space> before AND after the fraction




' regular fraction replace function
                ' dbRow.Item("fldDescription") = Regex.Replace(dbRow.Item("fldDescription"), _
                '   "(\d{2,}/\d|\d+\s+\d/\d+)", AddressOf StrFractionReplace)
                ' ===============================================
Private Function StrReplace(ByVal m As Match) As String

        Dim str As String = m.Value
        Dim strRep As String = ""

        If str.IndexOf(" "c) >= 0 Then
            Dim idx As Integer = str.IndexOf(" "c)
            strRep = str.Substring(0, idx) & "-" & str.Substring(idx + 1)
        Else
            Dim idx As Integer = str.IndexOf("/"c)
            strRep = str.Substring(0, idx - 1) & " " & str.Substring(idx - 1)
        End If

        Return strRep

    End Function


Thanks
fordraiders
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 18764083
Hi fordraiders;

OK lets say you have the following:

31/4   3 1/4
31/8   3 1/8
11/16   1 1/16
21/64   2 1/64
21/32   2 1/32

After being processed what should they look like?

Fernando
0
 
LVL 3

Author Comment

by:fordraiders
ID: 18764199
31/4   3~1/4
31/8   3~1/8
11/16   1~1/16
21/64   2~1/64
21/32   2~1/32

Need a Tilde ~

0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 18764681
Hi fordraiders;

This should do what you need without the need of the StrReplace function.

        dbRow.Item("fldDescription") = Regex.Replace(dbRow.Item("fldDescription"), _
                "\s(\d)(\d/\d+)\s", "$1~$2")

The above pattern will take values like

Values to be replaced            Will be replaced with
          31/4                                         3~1/4
          31/8                                         3~1/8
          11/16                                       1~1/16
          21/64                                       2~1/64
          21/32                                       2~1/32

Fernando
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

718 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