Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all,

I'm looking to read in a large text file.

I've tried doing it in two languages (C# and Perl) and both times, when I print out what I've read in it is only a portion of the file.

Does anyone have any ideas? Someone told me "Check out Stringbuilder" in C#, but if that is the solution, I'm not sure exactly what it is I'd do to make it work.

Any help is much appreciated. Thank you all.


Suraci
Posted
Updated 1-Dec-10 21:51pm
v2
Comments
JOAT-MON 1-Dec-10 21:58pm    
It might be helpful if you include a couple code snippets:
1. show how you are reading the file in (to see if you are getting the entire file)
2. show how you are printing the file out (to see if you are printing everything from the file)
Vasanth@n 2-Dec-10 0:21am    
Let me ask, how do you read the text file, and wat you are using to print the file? so that you can get more help.
Thomas Krojer 2-Dec-10 3:44am    
as JOAT-MON told:

1) show us the code you wrote
2) define: large. how large is 'large'?
Dalek Dave 2-Dec-10 3:51am    
Edited for Grammar and Readability.

As far as using StringBuilder, it is good to be aware of its uses even if it is not the problem. You can use it instead of string but it is not an exact replacement. On a high level, it simply makes better use of memory than a string because it does not recreate a string every time you modify its value. There are plenty of articles here and on the rest of the web comparing the 2 and supplying tutorials.
 
Share this answer
 
Heya

Here is two solutions:

(1)

Try reading X thousand lines at a time, save where you ended off, save X to a temp file, start reading again from i + X thousand lines for a further X + thousand lines, store in another temp file, and so on till the e.o.f. is reached. Write all the temp file data to a list buffer and delete temp files. I know that this is maybe not the best solution bad am sure it will work.

(2)

Otherwise, maybe how you read the text file is incorrect...
Check out this link below for a read from textfile function:
how to extract data from text file??[^]

Goodluck,
 
Share this answer
 
v3

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