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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Table Removes Spaces

Status
Not open for further replies.

mbde

Programmer
Mar 14, 2005
55
US
I have a text report. There is no delimiter, there is no fix format throughout the file. Once I can determine what line I am on I can figure out the format of that line. The problem curently is I am loading this file into a datatable. The datatable is removing leading spaces so the report that looks like

A(10 spaces)B(5 Spaces)C
(11 spaces)B(5 Spaces)C
(11 spaces)B(5 Spaces)C(5 spaces)D
(11 spaces)B(5 Spaces)C

Where A B C D are my data

in a data Table looks like
dt[0] = A(10 spaces)B(5 Spaces)C
dt[1] = B(5 Spaces)C
dt[2] = B(5 Spaces)C(5 spaces)D
dt[3] = B(5 Spaces)C


With Leading spaces removed. Can I stop a dataTable from acting like this? Now maybe the solution is not to load it into a data table but to return a open Stream, or a array of string[].

The other issue is that I need to move up and down through the file once I find a piece of informations.

Thank you.
 
To what I understand, the data file is space delimited where records have relatively random structure, but all possible structures are already identified.

You may consider 2 things: The parser, and the container of the parsed data.

For the parser, you can implement a class with several private methods corresponding to a particular record structure, and one public method as the entry point, where it will take a raw unparsed record, determine the record's format, and use the appropriate method for processing, probably persisting into a defined datastore, like a DataTable or an array of struct/class. Use a stream reader (coz it's cheaper and fast) to read each line and forward it to the parser.

Hope this helps! ;)
 
Thank you for the reply. It looks like I am going to have to load it into an array of strings. I do have two parser one that takes in the file and finds certain lines. And then a line parser that finds info within those lines.

I guess my underlying question is why does dataTables/dataAdapters remove leading spaces from the data they read in?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top