Hello all!

I am a programming n00b but learning more and more each day however I am stuck on something and I was hoping someone could provide some guidance. I am attempting to parse data that has been submitted by the user, or grabbed directly from a file, into a database. I have done some searching and it seems like this would be an easy thing to do if not for the fact that the data will have a slightly different format each time. For example:

TU 2167 TTT-WSD 1115 1344 129 40
TU 2986 WSD-VRE 1424 1535 111 502 0 502 0 1050 VRE 1425

Will sometimes look like this:

TU 2046 BH WSD-TTT 0924 0958 134 117
TU 2167 TTT-WSD 1115 1344 129 40 <-----NONE
TU 2986 WSD-VRE 1424 1535 111 502 0 502 0 1050 VRE 1425

Sometimes even slightly different than that.

I would like to be able to parse each value so that I can enter it into a database. However sometimes the data will have extra lines of characters before and/or after the parts I need, sometimes in between. The data does have a general order to it, it's just that sometimes values are not needed and thus left out. What class(es) should I be looking at to help me do this? I have been exploring the System.Text.RegularExpressions Match and MatchCollections classes but I'm not sure if I am heading in the right direction.

Thanks Again!

9 Years
Discussion Span
Last Post by Zambo

Regular expressions are a good start.

You might want to look at the factory pattern to parse each line.

Research on google for the factory pattern, basically it allows you to apply the same logic to each of these lines, making it easier to separate the pieces.


Very cool. I did some research on Google and I think I found a way for this to work with the factory pattern. Thanks for pointing me in the right direction!

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.