Handling Text data taken from file
-
Hello, I'm doing some free-time programming with learning objective (in c#), and one of my "projects" led me to separate data taken from a text file. Opening and retrieving data is no problem, I just put it into a ArrayList of string element for now. But when I want to separate the data from that ArrayList, the only solution I've come up with is as 'ugly' as this one: ArrayList stream = new ArrayList(); (some code here) foreach (string str in stream) { if (str.contains(some string)) { do something } else { if (str.contains(some other string)) { do other thing } else { (... even more if's) } } } I think there should be another way to do this, specially without so much "contains" operations that are time consuming. Can you give me some directions on how to break such items apart? I'm thinking this could also be used in other areas like socket communication. This feels like a very dumb question to me, but if I don't ask, I'll never learn. Thanks for any help you can give me.
-
Hello, I'm doing some free-time programming with learning objective (in c#), and one of my "projects" led me to separate data taken from a text file. Opening and retrieving data is no problem, I just put it into a ArrayList of string element for now. But when I want to separate the data from that ArrayList, the only solution I've come up with is as 'ugly' as this one: ArrayList stream = new ArrayList(); (some code here) foreach (string str in stream) { if (str.contains(some string)) { do something } else { if (str.contains(some other string)) { do other thing } else { (... even more if's) } } } I think there should be another way to do this, specially without so much "contains" operations that are time consuming. Can you give me some directions on how to break such items apart? I'm thinking this could also be used in other areas like socket communication. This feels like a very dumb question to me, but if I don't ask, I'll never learn. Thanks for any help you can give me.
Try using a List<string> template instead of an ArrayList. This class has a FindAll method that you could find to be helpful. Hope it helps.
Do your best to be the best
-
Try using a List<string> template instead of an ArrayList. This class has a FindAll method that you could find to be helpful. Hope it helps.
Do your best to be the best
It's a good sugestion, especially with the use of a "Predicate" in the search field. However, now I've got a new question... ;) Is it possible with .net 2.0 to get a range of data between known delimiters using predicate's? This would be soooo much cleaner. Thanks for the hint.
-
It's a good sugestion, especially with the use of a "Predicate" in the search field. However, now I've got a new question... ;) Is it possible with .net 2.0 to get a range of data between known delimiters using predicate's? This would be soooo much cleaner. Thanks for the hint.
I don't want to be rude, but take a look in Visual Studio's Help - MSDN, you'll get most of your answers there.
rsaint27 wrote:
Is it possible with .net 2.0 to get a range of data between known delimiters using predicate's?
I suppose you have seen that the FindAll method retuns a List<list>, so you can call the list's GetRange method...;)...would that help?
Do your best to be the best
-
I don't want to be rude, but take a look in Visual Studio's Help - MSDN, you'll get most of your answers there.
rsaint27 wrote:
Is it possible with .net 2.0 to get a range of data between known delimiters using predicate's?
I suppose you have seen that the FindAll method retuns a List<list>, so you can call the list's GetRange method...;)...would that help?
Do your best to be the best
-
Thanks again for your help, And :sigh: :-O I'll look better in reference documentation before posting here.
Try it...it doesn't hurt
Do your best to be the best