I have a text file and i want to Split the file into mulitple files based off the city( (all records with ' Logan ' as a city will be placed in one file, all records with ' Layton ' as a city should be in another file). and then create new files with the city name. Must be Be comma delimited instead of semi-colon delimited like the input file. Also the the header row, from the original file, copied to it so it appears at the top of the file.
I think i copy the header to a file.
I have never worked with teh file system object before.
I am able to read the file and also changed the semi colon to a comma in the file.
This is how the text file looks like(just a junk data)
The text file looks up like this
SSN;FirstName;LastName;DOB
;City;Stat
e;Zip;Bala
nce
111222333;Suzy;Adams;05/15
/1977;Salt
Lake City;UT;84054;2000.00
111333444;Brady;Broom;03/1
6/1978;Pro
vo;UT;8405
4;4300.00
111444555;Andrew;Packard;0
2/06/1980;
Salt Lake City;UT;84034;2340.00
111555666;Ralph;Vunderly;0
1/15/1983;
Provo;UT;8
4023;2000.
00
111666777;Jay;Hack;12/12/1
956;Layton
;UT;84043;
20.00
111777888;Steven;Nielsen;1
0/31/1976;
Logan;UT;8
4065;2000.
00
111888999;Debbie;DuJanivic
;05/05/197
7;Salt Lake City;UT;84032;2450.00
Thi si my code looks like
Imports System
Imports System.IO
Imports System.Collections
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objReader As New StreamReader("c:\test.txt"
)
Dim sLine As String = ""
Dim arrText As New ArrayList()
Do
sLine = objReader.ReadLine()
If Not sLine Is Nothing Then
sLine = Replace(sLine, ";", ",")
arrText.Add(sLine)
End If
Loop Until sLine Is Nothing
objReader.Close()
For Each sLine In arrText
' Console.WriteLine(sLine)
' MsgBox(sLine)
'Response.Write(sLine)
Dim furst As String = arrText(0)
Response.Write(furst)
Next
'Response.Write(sLine)
Response.Write(furst)
Console.ReadLine()
End Sub
End Class
Start Free Trial