add [DOT] to text line

textfile , vb.net Kuala Lumpur, Malaysia
  • 8 years ago

    i have a combination of lines like this:

    X200876Y-140576 X220177Y12467

    and i want to make this lines to be like this

    X200.876 Y-140.576 X220.177 Y124.67

    The program should works like this. It should read the line and it shoud add "." after 3 numbers from X and for Y also same thing After Y it should count 3 numbers and add [DOT] and avoid any other character after Y only count numbers. Dim lines() As String = System.IO.File.ReadAllLines("C:\kaya.txt")

        Dim sv As StreamWriter = File.CreateText("C:\\kaya.txt")
    
        Dim line As String
        For Each line In lines
    
            Dim pos1 As Integer = line.LastIndexOf("X") + 1
    
            Dim pos2 As Integer = line.LastIndexOf("Y") + 1
    
            Dim leng As Integer = line.Length
    
            Dim fstnum As String = line.Substring(pos1, pos2 - pos1 - 1)
    
            Dim sndnum As String = line.Substring(pos2, leng - pos2)
    
            If IsDigits(fstnum) Then
                fstnum = "X" + fstnum.Insert(fstnum.Length - 3, ".") + " " '<--blank space added
    
            Else
                fstnum = "X" + fstnum + " " '<--blank space added
            End If
            If IsDigits(sndnum) Then
                sndnum = "Y" + sndnum.Insert(sndnum.Length - 3, ".")
            Else
                sndnum = "Y" + sndnum
            End If
            editedLine = fstnum + sndnum
    
            sv.WriteLine(editedline)
        Next
    
        sv.Close()
    
    
    End Sub
    Private Shared Function IsDigits(ByVal value As String) As Boolean
        If String.IsNullOrEmpty(value) Then
    
            Return False
        End If
    
        Dim regexp As Regex = New System.Text.RegularExpressions.Regex("^[0-9,-]*$")
    
        Return regexp.Match(value).Success
    

    Can any one help me to solve this problem Thank you

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programs must be written for people to read, and only incidentally for machines to execute.”