troubleshooting Question

Revise procedure to Search and replace .

Avatar of Fordraiders
FordraidersFlag for United States of America asked on
Visual Basic.NET
14 Comments2 Solutions220 ViewsLast Modified:
Vb.Net 2003

What I have:
MyData.txt   file

3 columns of data :  seperted by a Pipe Delimiter

LAWSON |12324R5|DRILLBIT station.bit standard length
LAWSON |32DE45|DRILLBIT remote.bit long length
UNION BUTTERFIELD|54667| 1.2  A.2  inches in length ' <---  the code should leave this . alone because it has a numeric to left and/or right
etc......

=============================================
What I need:
To revise this procedure

I now need this procedure to look for a    .    <------   dot  or period

If it finds a dot  AND it is surronded by an alpha character to the left AND to the right.
DELETE the period/dot ,  If not leave the line alone
' current  routine   **********************************
'===== this routine here is looking for double quotes and replacing
' =====if it finds a numeric to the left it replaces the double quotes
'===== with inch
Dim fileName As String = "C:\Samples\ReplaceTest.txt"

        Dim sr As New System.IO.StreamReader(fileName)
        Dim lines() As String = Split(sr.ReadToEnd.Trim.TrimEnd(vbCr).TrimEnd(vbLf), vbCrLf)
        sr.Close()

        Dim sb As System.Text.StringBuilder
        Dim fields() As String
        For i As Integer = 0 To lines.GetUpperBound(0)
            fields = lines(i).Split("|")
            ' chr(34) = double quotes
            If fields.GetUpperBound(0) >= 2 Then
                sb = New System.Text.StringBuilder(fields(2))
                For x As Integer = 1 To sb.Length - 1
                    If sb.Chars(x) = Chr(34) Then
                        If Char.IsDigit(sb.Chars(x - 1)) Then
                            sb.Remove(x, 1)
                            sb.Insert(x, " inch")
                        End If
                    End If
                Next

                fields(2) = sb.ToString
            End If

            lines(i) = String.Join("|", fields)
        Next

        Dim sw As New System.IO.StreamWriter(fileName)
        sw.WriteLine(String.Join(vbCrLf, lines))
        sw.Close()

Thanks
fordraiders

ASKER CERTIFIED SOLUTION
TimCottee
Applications and Integrations Consultan

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros