Handling text data retrieved 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 ListArray<> of string element for now. But when I want to separate the data from that ListArray, the only solution I've come up with is as 'ugly' as this one: (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 ListArray<> of string element for now. But when I want to separate the data from that ListArray, the only solution I've come up with is as 'ugly' as this one: (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.
Have you come up with any good ideas?
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon