beginners problem - files

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 17
Reputation: stewie griffin is an unknown quantity at this point 
Solved Threads: 0
stewie griffin stewie griffin is offline Offline
Newbie Poster

beginners problem - files

 
0
  #1
Aug 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 39
Reputation: nvmobius is an unknown quantity at this point 
Solved Threads: 4
nvmobius nvmobius is offline Offline
Light Poster

Re: beginners problem - files

 
0
  #2
Aug 11th, 2008
huh?

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

  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. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC