It's just a simple code but I don't know where I'm missing quotations or etc
My error lies here: case "000\";

Any help is appreciated! Thanks!

 MatchCollection matches1 = Regex.Matches(strFields[3], @"\d{3}\\");
                                            string range = matches1[0].Value;
                                            switch (range)
                                            {
                                                case "000\";
                                                    strAdType += "A";
                                                    break;
                                                case "001\":
                                                    strAdType += "B";
                                                    break;
                                                case "002\":
                                                    strAdType += "C";
                                                    break;
                                                case "003\":
                                                    strAdType += "D";
                                                    break;
                                                case "004\":
                                                    strAdType += "E";
                                                    break;

                                            }

Recommended Answers

All 3 Replies

You can't use strings in case statements -- only integers and single characters. If you need strings the only way to do it is with a series of if/else
statements.

"000\";

That is also wrong because the compiler will attempt to use \ as an escape character and out " as part of the string iteself. What you want is one of these two

"000\\"; // make \ part of the string

"000\""; // make " part of the string

You most assuredly can use string in case statements. The restriction is that the values must be constants at compile time.

Your problem is that the \ character is an escape character and it thinks you are looking for 000" and there is no closing quote for the string so the rest of the code is garbage. Either double up the \ or prefix it with an @

case "000\\": blah; break;
case @"001\": blah2; break;

And please tell me you aren't building strings by appending characters. Use StringBuilder for that.

thanks for the detailed explanation! i gettit now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.