?
Solved

Update Regx expression and Function

Posted on 2007-03-21
3
Medium Priority
?
167 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

770 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