Reading files with delimeters

  • Thread starter Thread starter R.A.
  • Start date Start date
R

R.A.

Hi

Is there some support reading binary files with delimeters and getting the
data in string arrays based on the delimiters, using c#?


Thanks
 
R.A,
If you're looking to just solve the problem quick and dirty, I'd
use a reader to read lines fro a file (assuming that the line represents
a record) and use the string.split method to split based on delimiters.
If you had time on your hands and are an OO purist, Id suggest
create a DelimiterReader class that does a special read based on
delimiters.
Hope that helps
 
..Split() is your winner. You specify the delimters you want and it returns
back a string array.

For example, to split up a tab/comma-delmited line you would do

string[] sa = mystring.Split('\t', ',');
 
R.A.,

There is not support for this inherently in the framework, but you can
easily do it. Basically, read through each byte in the file, storing it in
an ArrayList until you come to your delimiter. Then, copy the contents of
the arraylist to a byte array, and pass that array to the specific encoder
class which will decode the bytes into strings (ASCIIEncoder, for example).
Then, clear your ArrayList, skip the delimiter, and then start over.

Hope this helps.
 
Back
Top