-
Oct 8th, 2014, 01:35 PM
#1
Thread Starter
Hyperactive Member
Split line from big text file
I need to split line from one big text file.(80MB)
For example, text file look like below
ST*837*000008~BHT*0019*00*1*20140205*1020*RP~REF*87*004010X098~
I need code to update it as below based on "~" letter.
ST*837*000008~
BHT*0019*00*1*20140205*1020*RP~
REF*87*004010X098~
How to do it?
-
Oct 8th, 2014, 01:48 PM
#2
Re: Split line from big text file
Are you talking about reading a text file that is a single line, then splitting up that text file by the ~ character and storing the splits as new lines in the same file? If so look at this example:
Code:
Option Strict On
Option Explicit On
Module Module1
Sub Main()
Dim t As Threading.Thread = New Threading.Thread(Sub() SplitFile("my_file_here.txt", "~"c))
t.Start()
Console.ReadLine()
End Sub
Private Sub SplitFile(ByVal path As String, ByVal delimiter As Char)
Console.WriteLine("Reading file.")
Dim contents As String = My.Computer.FileSystem.ReadAllText(path)
Dim newContents As String = String.Empty
Console.WriteLine("Splitting contents by the " & "~" & " character.")
For Each line As String In contents.Split({delimiter}, StringSplitOptions.RemoveEmptyEntries)
newContents &= line & Environment.NewLine
Next
My.Computer.FileSystem.WriteAllText(path, newContents, False)
Console.WriteLine("Finished editting the file.")
End Sub
End Module
-
Oct 8th, 2014, 02:51 PM
#3
Thread Starter
Hyperactive Member
Re: Split line from big text file
Thank you. It works great!
-
Oct 8th, 2014, 02:54 PM
#4
Re: Split line from big text file
There is one typo I made, on this line:
Code:
Console.WriteLine("Splitting contents by the " & "~" & " character.")
It should be this:
Code:
Console.WriteLine("Splitting contents by the " & delimiter.ToString & " character.")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|