I have to agree with Sebastian's comment. This can be accomplished using simple Split
operations.
private static bool Check(string input)
{
int count = 0;
foreach (string segment in input.Split('~'))
{
string[] tokens = segment.Split('*');
if (tokens[0] == "AAA")
{
count++;
if (count == 3)
{
if (tokens[3] == "63") return true;
else return false;
}
}
}
return false;
}
EDIT: Since you want fewer lines of codes, how about LINQ?
private bool Check(string input)
{
return input.Split('~').Select(x => x.Split('*')).Any(x => x.Length >= 4 && x[0].Equals("AAA") && x[3].Equals("63"));
}
EDIT2: For completeness, here's a Regex solution as well:
private bool Check(string input)
{
return Regex.IsMatch(input, @".*~AAA\*([^\*~]*\*){2}63.*");
}