Thursday, September 15, 2016

parse text file


Imports System.IO
Module Module1

    Sub Main()

        Dim fileO As System.IO.StreamWriter
fileO = My.Computer.FileSystem.OpenTextFileWriter("D:\O.txt", True)


        For Each line As String In File.ReadLines("d:\1.txt")
          Dim i As Int16 = GetNthIndex(line,"""",4)
           Dim s1 As String = Left(line,i)
            Console.WriteLine(s1)
            Dim j As Int16 = 0
            Dim s2 As String = Right(line, i)
            s2 = line.Substring(i)
            Console.WriteLine(s2)
            Dim s3 As String = line.Substring(i)
            'Dim s4 As string
            Dim s4 As String = line.Substring(i+1)
            Dim s5 As String = s1 + chr(34) + "," + Chr(34) + "name:" +Chr(34) + ":" +chr(34) + s4
            Console.WriteLine(s5)
            fileO.WriteLine(s5)
           ' Console.WriteLine(s2)
        Next
        fileO.Close()
    End Sub

    Public Function GetNthIndex(s As String, t As Char, n As Integer) As Integer
    Dim count As Integer = 0
    For i As Integer = 0 To s.Length - 1
            Console.WriteLine(s(i))
        If s(i) = t Then
            count += 1
            If count = n Then
                Return i
            End If
        End If
    Next
    Return -1
End Function

End Module

No comments:

Post a Comment