0

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

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by nvmobius
0

huh?

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

List<string> a = new List<string>();
            List<string> b = new List<string>();

            using ( StreamReader reader = new StreamReader(File.OpenRead(FILE_PATH)) ) {
                string line = null;
                string[ ] parts = null;

                try {
                    while ( (line = reader.ReadLine()) != null ) {
                        if ( String.IsNullOrEmpty(line) ) continue;

                        parts = line.Split(new char[ ] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                        if ( parts.Length >= 1 ) {
                            a.Add(parts[0]);

                            if ( parts.Length >= 2 ) {
                                b.Add(parts[1]);
                            }
                        }
                    }
                } catch ( Exception exception ) {
                    throw exception;
                } finally {
                    reader.Close();
                }
            }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.