0

Basically im using switch case to set strOutput. But i get duplicate values instead..

strInput="00\~01\02~"

This is what i get:
A
AB
ABC

My desired outcome is:
A
B
C

 MatchCollection matches = Regex.Matches(strInput, @"\d{2}\\");
                                                string range = matches[0].Value;

                                                switch (range)
                                                {
                                                    case "00\\":
                                                        strOutput += "A";
                                                        break;
                                                    case "01\\":
                                                        strOutput += "B";
                                                        break;
                                                    case "02\\":
                                                        strOutput += "C";
                                                        break;

                                                }
                                                #endregion
                                                write.WriteLine(strOutput);
2
Contributors
2
Replies
8
Views
3 Years
Discussion Span
Last Post by Jahliah
0

My bad. I should have posted my full codes.
strInput= 00\,one,two~01\,one,two~02\,one,two~

string[] line = strInput.Split('~');
foreach (string part in line)
 {

 string[] strInput = part.Split(',');

MatchCollection matches = Regex.Matches(strFields[0], @"\d{2}\\");

string range = matches[0].Value;
switch (range)
 {
  case "00\\":
  strOutput += "A";
  break;

  case "01\\":
  strOutPut += "B";
  break;

  case "02\\":
  strOutput += "C";
  break;

 }

 write.WriteLine(strOutput);

                                            }
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.