Reading txt file

Bigbadborris

Active member
Joined
Aug 21, 2013
Messages
35
Programming Experience
Beginner
Hi all

I have a txt file that holds contact details for my customers each record is 581 Characters in lenght.Each record is appended on to the end of the last.
This file was created in an old dos program.
Any ideas how I could read the file and record each 581 Character record in a different txt file with each record on a different line.

Unfortunatly I cant attach the txt file as the information is very sensitive.

Many Thanks in advance
 
Wriiting line by line as you read:
Using reader As New StreamReader("input path here"),
      writer As New StreamWriter("output path here")
    Const BUFFER_SIZE As Integer = 581
    Dim buffer(BUFFER_SIZE - 1) As Char
    Dim charsRead = reader.Read(buffer, 0, BUFFER_SIZE)

    Do While charsRead = BUFFER_SIZE
        writer.WriteLine(New String(buffer))
        charsRead = reader.Read(buffer, 0, BUFFER_SIZE)
    Loop
End Using
Writing in a single batch when you finish reading:
Dim lines As New List(Of String)

Using reader As New StreamReader("input path here")
    Const BUFFER_SIZE As Integer = 581
    Dim buffer(BUFFER_SIZE - 1) As Char
    Dim charsRead = reader.Read(buffer, 0, BUFFER_SIZE)

    Do While charsRead = BUFFER_SIZE
        lines.Add(New String(buffer))
        charsRead = reader.Read(buffer, 0, BUFFER_SIZE)
    Loop
End Using

File.WriteAllLines("output path here", lines)
 
Wriiting line by line as you read:
Using reader As New StreamReader("input path here"),
      writer As New StreamWriter("output path here")
    Const BUFFER_SIZE As Integer = 581
    Dim buffer(BUFFER_SIZE - 1) As Char
    Dim charsRead = reader.Read(buffer, 0, BUFFER_SIZE)

    Do While charsRead = BUFFER_SIZE
        writer.WriteLine(New String(buffer))
        charsRead = reader.Read(buffer, 0, BUFFER_SIZE)
    Loop
End Using
Writing in a single batch when you finish reading:
Dim lines As New List(Of String)

Using reader As New StreamReader("input path here")
    Const BUFFER_SIZE As Integer = 581
    Dim buffer(BUFFER_SIZE - 1) As Char
    Dim charsRead = reader.Read(buffer, 0, BUFFER_SIZE)

    Do While charsRead = BUFFER_SIZE
        lines.Add(New String(buffer))
        charsRead = reader.Read(buffer, 0, BUFFER_SIZE)
    Loop
End Using

File.WriteAllLines("output path here", lines)

Absolutly spot on, worked like a dream

Many Thanks
 
Back
Top