Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, i have a large .csv file that contains a lot of Data. I would like to look into this file using a particular field.

For example, my file looks a bit like this: location; company; product code, department, cost, price

So Id like to try with the product code, and if it finds it, it takes the entire line and he appears.

So if I have a file that looks like this.

left wall; wal-mart; 0000 0001; electronic; 7.99; 9.99;
right wall pepsi; 8883 0012; food; 0.01; 3.99;
upper; mcdo; 9981 0011; food; 0.05; 1.99;

So if I search for the product code 0000 0001 it will display left wall, wal-mart, 0000 0001 Electronic 7.99 9.99

Is it better to search directly in the file or transfer it in a string and search in it?

So yeah, if anyone have a link or a algorithm it would be very appreciated!

Thank you guys!

What I have tried:

I try a lot of search on google and didn't find what im looking for!
Posted
Updated 28-Sep-16 11:22am

None of above! The fastest way to search data in delimited text files is to use OleDb[^].

Check this:
Read Text File (txt, csv, log, tab, fixed length)[^]
Read Text File Specific Columns[^] - complete, working code!

For further details, please see:
Much ADO About Text Files[^]
Schema.ini File (Text File Driver)[^]
ADO.NET Overview[^]

Try! Good luck!
 
Share this answer
 
2 possibilities
- you have multiple researches to do:
loading the file in memory will make a large footprint, but will speedup researches after the first one.
A sophisticated handling like in Solution 1 will spend time when handling the file and save time with every search.

- you have a single search to do:
loading the file at once will have a large memory footprint but will not save time because you search only once.
loading line by line will have a small memory footprint will about same speed as loading the whole file.
For a single search, simple brut force is about the best.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900