When I do this, I get a compile error that says, "Cannot implicitly convert type 'System.Text.RegularExpressions.Match' to 'bool' on this line:
if (vt.Expect(new Regex(matchPattern), 5000))
Here's my code as compiled:
string matchPattern = string.Format("Seq=[0-9]~Queue=[0-9]~Pri=[0-9]~Date=[0-9]/[0-9]/[0-9]~Time=[0-9]:[0-9]:[0-9]~Running=[0-9]~Cancel=[0-9]~Stat=[A-Za-z]~Job=", jobName);
if (vt.Expect(new Regex(matchPattern), 5000))
{
matchPattern = string.Format("Seq=([0-9])~Queue=[0-9]~Pri=[0-9]~Date=[0-9]/[0-9]/[0-9]~Time=[0-9]:[0-9]:[0-9]~Running=[0-9]~Cancel=[0-9]~Stat=[A-Za-z]~Job=", jobName);
Match match = Regex.Match(response, matchPattern);
if (match.Success)
{
seqNumber = int.Parse(match.Groups[1].Value.Trim());
string writeln = string.Format("Job Started ! name: {0} Seq: {1}", jobName, seqNumber);
Console.WriteLine(writeln);
}
else
{
Console.WriteLine("Did not match string: " + m_ServerResponse);
}
}
FYI, I do a second pattern match b/c I want to grab the Seq (number) for use later in my app.
I've also tried this, but get the same compile-time error:
Regex mtch = new Regex(matchPattern);
if (vt.Expect(mtch, 5000))
{
//string matchPattern = string.Empty;
matchPattern = string.Format("Seq=([0-9])~Queue=[0-9]~Pri=[0-9]~Date=[0-9]/[0-9]/[0-9]~Time=[0-9]:[0-9]:[0-9]~Running=[0-9]~Cancel=[0-9]~Stat=[A-Za-z]~Job=", jobName);
Regex match = Regex.Match(response, matchPattern);
if (match.Success)
{
seqNumber = int.Parse(match.Groups[1].Value.Trim());
string writeln = string.Format("Job Started ! name: {0} Seq: {1}", jobName, seqNumber);
Console.WriteLine(writeln);
}
else
{
Console.WriteLine("Did not match string: " + m_ServerResponse);
}
}
Additionally, I've tried:
bool matched = vt.Expect(new Regex(matchPattern), 5000);
with the same compile error.
However, the following stand-alone code DOES NOT throw an error:
vt.Expect(new Regex(matchPattern), 5000);
But this line isn't useful.
HTH and thanks for the quick replies. This one might be more difficult to solve, as this is a C# error, not a Rebex thing.
Chew