J
jp2msft
Two part question:
1. Is Regex more efficient than manually comparing values using Substring?
2. I've never created a Regex expression. How would I use regex to do the
equivalent of what I have coded using Substrings below?
Thanks in advance for your help and your time.
1. Is Regex more efficient than manually comparing values using Substring?
2. I've never created a Regex expression. How would I use regex to do the
equivalent of what I have coded using Substrings below?
Code:
string s = TextBox1.Text.ToUpper();
string ch = s.Substring(0, 1); // read first character [B,C,X]
if ((ch == "B") || (ch == "C") || (ch == "X")) {
ch = s.Substring(1, 1); // read second character [P,0,5,7]
if ((ch == "P") || (ch == "0") || (ch == "5") || (ch == "7")) {
if (12 < len) {
ch = " "; // check for spaces in 2 places
if ((s.Substring(7, 1) == ch) && (s.Substring(12, 1) == ch)) {
if (len == 15) {
ok = IsNumeric(new string[] { s.Substring(2, 5), s.Substring(8,
4), s.Substring(13, 2) });
} else {
Console.WriteLine("Non-numeric data found in numeric section.");
}
}
} else {
Console.WriteLine("There should be blanks at positions 8 and 13.");
ok = false;
}
}
} else {
Console.WriteLine("Second letter should be [P, 0, 5, or 7].");
ok = false;
}
} else {
Console.WriteLine("First letter should be [B, C, or X].");
ok = false;
}
Thanks in advance for your help and your time.