"va*******@gmai l.com" wrote:
Hi,
I want to check for the absence of a string in regular expression. For
example, if the string is "Error opening file: Permission denied.
Aborting.", I want to check for absence of the string "Permission ". I
have tried many possibilities without success.
Thanks for any help,
Varun Sud
Hi Varun,
You can achieve the same using the code snippet below. You can choose either
string basic operation or regex match.
<CODE>
string str = "Error opening file: Permission denied. Aborting.";
string pattern = "Permission ";
// Using RegEx methods
Regex reg = new Regex(pattern);
if(! reg.IsMatch(str ))
Console.WriteLi ne("Not Found (RegEx operation)");
else
Console.WriteLi ne("Found Match (RegEx operation)");
// Using string methods
if(str.IndexOf( pattern) < 0)
Console.WriteLi ne("Not Found (string operation)");
else
Console.WriteLi ne("Found Match (string operation)");
</CODE>
Hope it will help.
--
Cheers,
Rahul Anand