Solved

Update Regx expression and Function

Posted on 2007-03-21
3
157 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
  • 2
3 Comments
 
LVL 62

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 62

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

896 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

11 Experts available now in Live!

Get 1:1 Help Now