2

I have a string which contains the following output

login;windows
db;sql
audit;failure

how do I check if this string contains the word "audit;failure"?

I have use the following code but was not successful:

 currLine = sr.ReadToEnd();
 string[] splited = Regex.Split(currLine, "~~~~~~~~~~~~~~");
 case1 = splited[0];
 string case1 = "";
 string pattern1 = "audit;failure";
 if (Regex.IsMatch(case1, pattern1)){
 console.writeline("success"!);
}

I must search through the variable case1 and not the string currLine thaks in advance! :D

1

4 Answers 4

3

Also make sure that you remove the line string case1 = "";

if(case1.Contains("audit;failure"))
   console.writeline("success"!);
Sign up to request clarification or add additional context in comments.

Comments

0

I think you just need to adjust case1 string ........

 string case1 = "";
 currLine = sr.ReadToEnd();
 string[] splited = Regex.Split(currLine, "~~~~~~~~~~~~~~");
 case1 = splited[0];
 string pattern1 = "audit;failure";
 if (Regex.IsMatch(case1, pattern1)){
 console.writeline("success"!);
}

Comments

0

Simply use String.Contains(), use a code like follows

if(sr.Contains("audit;failure")
{

}

Comments

0

One way to do it would be to split this first into the lines.

string[] lines = sr.split (new string[]{ Environment.LineBreak});
foreach(string line in lines){
    string[] parts = line.split(new char[] {';'});
    if(parts[0] == "audit")
        return parts[1];
}
return "not set";

This will return whatever stands behind "audit" and is easily adaptable to return whatever you need. The final return will be triggered if no audit-line was present.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.