943,737 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 400
  • C# RSS
Aug 11th, 2008
0

beginners problem - files

Expand Post »
Hi ,
i want to load txt file that build from tow columns separator by 'tab' every column go to different list how can I do it ? how can I read until 'tab' and then continue from my last stop.
example to the file
one 1
tow 2
three 3
Similar Threads
Reputation Points: 64
Solved Threads: 1
Light Poster
stewie griffin is offline Offline
35 posts
since Jul 2008
Aug 11th, 2008
0

Re: beginners problem - files

huh?

I'm gonna guess what the heck you mean here, and hand you an answer.

C# Syntax (Toggle Plain Text)
  1. List<string> a = new List<string>();
  2. List<string> b = new List<string>();
  3.  
  4. using ( StreamReader reader = new StreamReader(File.OpenRead(FILE_PATH)) ) {
  5. string line = null;
  6. string[ ] parts = null;
  7.  
  8. try {
  9. while ( (line = reader.ReadLine()) != null ) {
  10. if ( String.IsNullOrEmpty(line) ) continue;
  11.  
  12. parts = line.Split(new char[ ] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
  13.  
  14. if ( parts.Length >= 1 ) {
  15. a.Add(parts[0]);
  16.  
  17. if ( parts.Length >= 2 ) {
  18. b.Add(parts[1]);
  19. }
  20. }
  21. }
  22. } catch ( Exception exception ) {
  23. throw exception;
  24. } finally {
  25. reader.Close();
  26. }
  27. }
Reputation Points: 11
Solved Threads: 4
Light Poster
nvmobius is offline Offline
39 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Windows application on a server
Next Thread in C# Forum Timeline: How to protect my exe file in cd?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC