Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# syntax question: switch and IndexOf
Message
From
04/05/2005 12:34:50
 
 
To
04/05/2005 12:09:28
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01010821
Message ID:
01010844
Views:
15
Hey Alex,

I think the only way you could use a switch is if you could easily strip off the country or region from the beginning of the file name. Then you could use FileName.Substring() in the switch and the types in the case. If you can't do that easily enough, then I think you're stuck with the if/else construct ... and it's not that bad really ... much easier to read than RegEx stuff!!! Also, I don't see how Enums will help either.

~~Bonnie



>Thorny C# commands and syntax problem I encountered today while working on a reall app at the same time I teach myself C# and .Net:
>
>Situation:
>
>I am looking on a folder for delimited files that will be received daily. These I will parse and process.
>There are 11 types of files with 11 slightly different file structures. These go to a SQL Server database for later reporting (11 different reports) based on this data. So far it's an easy proposition and a good simple app to teach myself some .NET
>
>The only way to tell the 11 different files from each other is the file name. File names are very similar (I don't have any choice or control as they come from a mainframe).
>
>Some sample filenames:
>"Caribbean Generic MCC C&S Merch2005-03-06 22.35.15.250.txt"
>"Central Am Missing & Invalid C&S Merch2005-03-05 04.12.09.578.txt"
>"Mexico Illogical Auth Rule B&C2005-03-07 22.29.21.953.txt"
>"Mexico Illogical C&S Rule A&B2005-04-07 22.11.54.765.txt"
>
>The country or region is ignored as it is included in a data field inside the file. Date and time is also ignored as it does not tell me the type of file.
>
>I divided all 11 possible names into:
>"Missing & Invalid C&S Merch"
>"Illogical Auth Rule B&C"
>"Illogical C&S Rule A&B"
>etc.
>
>and established a number for each in code (01-11)
>
>I search with IndexOf and see if the first type is found. So far so good. Now I'd have to test against all the other ones until found. Not cool.
>
>
>Question:
>
>I'd like a switch construct to determine which of the 01 to 11 types it is, so I can direct to the method that processes the proper data file structure. But 'switch 'in C# can't do it. In VFP 'DO CASE' I can test each case to see if filename matches one of the 11 patterns. In C# 'switch' the test is done only once.
>
>Anybody has a good idea of how to approach the problem? Maybe creating an Enum for the 11 types? Some complicated RegEx? I'd like to avoid using RegEx (too cryptic) if possible.
>
>
>In short:
>
>All I need to know, in a fast and graceful way, is test each actual filename against the 11 possible cases and find which one it matches.
>
>TIA,
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform