Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

special character delimited flat file

Status
Not open for further replies.

Ronze55

MIS
Jul 9, 2004
54
US
Hello everyone,

I am looking for away to parse a flat file (.in) which is delimited by the '|' character. the files will on occasion hold data that contains a comma within as part of the field.

I am using VB.net and will hook up to the file using OLEDB. I haven't built much of it yet so I really don't have much to put down as far as code. any help is greatly appreciated.

thanks in advanced
ronze
 
I've used OLEDB before successfully to read text files. What I was not able to do was to specify that the delimiter was anything other than the default (a comma, I think).

However, this article shows you everything, including custom delimiters., if you follow all the links. (It came from the Google search "visual basic read text file using OLEDB", by the way).


That article is in C++ (I think). There are plenty in VB, if you look, but they generally don't talk about changing the delimiter.


Mark

Mark [openup]
 
Maybe use the StreamReader class to read a line of text and String.Split to get a string array using the pipe delimeter ?
 
shelton,

thanks for your recomendation. I have looked up streamreader and am familiar with peek so I understand this port. can you help me a bit more on the pipe delimeter part?

thanks again to both of you for replying
Ronze
 
A bit of code below. This assumes you have a text file called Test.txt in your C drive in the following format:

1|John|Smith
2|Fred|Jones

Code:
Dim sr As New System.IO.StreamReader("C:\Test.txt")

Dim s() As String

Do While sr.Peek <> -1

    s = sr.ReadLine.Split("|")

    MessageBox.Show(String.Format("{0} - {1} {2}", s(0), s(1), s(2)))

Loop
Obviously this just shows a message box, but once you have the string array you can do what you want with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top