Validate a substring from a list

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to validate a 2-character substring against a list of 13
2-character codes without a select statement to a table or parsing an array?
Something like ... myChars in ("aa", "bb", "cc")...
 
Is it possible to validate a 2-character substring against a list of 13
2-character codes without a select statement to a table or parsing an
array?
Something like ... myChars in ("aa", "bb", "cc")...

What do mean by "parsing an array"?

You could just put your list of substrings to match in an array, then use
Array.Exists() or Array.IndexOf() to see if the substring is in the
array. There are similar methods you could use with the List<> class.
Alternatively, you could probably use the RegEx class to see if there's a
match. I think you can use a search string like "[aa|bb|cc|...]" on your
string; if your string is only two characters long and there's a match,
then you know your substring was one of the items in the RegEx.

Personally, I'd use the array look-up method, but I suppose if you're
really against using an array or List<>, RegEx would do.

Basically, there's any number of ways to do what you want. Without a more
precise problem description, it's hard to offer anything other than very
general advice.

Pete
 
Not sure if I quite understand what you are trying to do but something like
this should work.

string[] twoCharString = { "AA", "BB", "CC", "DD" };
MessageBox.Show((twoCharString.Contains("BB") ? "Yes" :
"Nope"));

You can use the Contains method of a string.

-Pramod Anchuparayil
 
THat should do it. Thank you, sir.
--
Harry E Vermillion
IT2
Division of Wildlife
State of Colorado


Pramod Anchuparayil said:
Not sure if I quite understand what you are trying to do but something like
this should work.

string[] twoCharString = { "AA", "BB", "CC", "DD" };
MessageBox.Show((twoCharString.Contains("BB") ? "Yes" :
"Nope"));

You can use the Contains method of a string.

-Pramod Anchuparayil

Harry V said:
Is it possible to validate a 2-character substring against a list of 13
2-character codes without a select statement to a table or parsing an
array?
Something like ... myChars in ("aa", "bb", "cc")...
--
Harry E Vermillion
IT2
Division of Wildlife
State of Colorado
 
Back
Top