Solved

Update Regx expression and Function

Posted on 2007-03-21
3
162 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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