More ArrayList problems.
-
Hi, I have an ArrayList populated by a text file made up of lines comprising 3 columns: ID, Duration, Description. They roughly look like this 12345678.abc 020 This is a description 12345678.abd 030 This is another description etc The ID column is always 12 characters, the duration is always 3 numbers, the description obviously can change from line to line. Each line of the text file is read into the array in sequence, I need to be able to break each element of the ArrayList into the appropriate columns. The problem is with the description column as it contains multiple spaces. I can't work out how to break each string into the columns required Please can anyone help? Thank you very much in advance Scott
-
Hi, I have an ArrayList populated by a text file made up of lines comprising 3 columns: ID, Duration, Description. They roughly look like this 12345678.abc 020 This is a description 12345678.abd 030 This is another description etc The ID column is always 12 characters, the duration is always 3 numbers, the description obviously can change from line to line. Each line of the text file is read into the array in sequence, I need to be able to break each element of the ArrayList into the appropriate columns. The problem is with the description column as it contains multiple spaces. I can't work out how to break each string into the columns required Please can anyone help? Thank you very much in advance Scott
If the format is as you described then using substring would probably be easiest.
string s = "12345678.abc 020 This is a description"; string id = s.Substring(0, 12); string duration = s.Substring(13, 3); string description = s.Substring(17);
You might want to put this in a catch block if there is a chance an line is incorrect. For more complex string manipulation you might want to look at regular expressions. -
If the format is as you described then using substring would probably be easiest.
string s = "12345678.abc 020 This is a description"; string id = s.Substring(0, 12); string duration = s.Substring(13, 3); string description = s.Substring(17);
You might want to put this in a catch block if there is a chance an line is incorrect. For more complex string manipulation you might want to look at regular expressions. -
Thank you for replying, I see where you're going with this. It does however raise another question in as much as I then need to bind those strings into a datagrid under the same headings. Any ideas how?
Create a class to store the id,duration and description. Then create an arraylist with instances of that class instead of strings.
-
Hi, I have an ArrayList populated by a text file made up of lines comprising 3 columns: ID, Duration, Description. They roughly look like this 12345678.abc 020 This is a description 12345678.abd 030 This is another description etc The ID column is always 12 characters, the duration is always 3 numbers, the description obviously can change from line to line. Each line of the text file is read into the array in sequence, I need to be able to break each element of the ArrayList into the appropriate columns. The problem is with the description column as it contains multiple spaces. I can't work out how to break each string into the columns required Please can anyone help? Thank you very much in advance Scott