Mara
Mara

Reputation: 365

Check that the text contains a string

I have a list of strings that I check to see if they contain certain text, now I have a problem with this string which looks like this:

00:43:00\nExampleText 

Now i want to find that text, something like this

if (cevent.EventText.Contains("ExampleText ") || cevent.EventText == "nExampleText2"){

}

Of course this doesn't work with Contains, how else could I handle this?

Something like Likes: %nExampleText% ?

Upvotes: 0

Views: 130

Answers (2)

Pedro Isaaco
Pedro Isaaco

Reputation: 404

Actually this worked pretty good in my case. Please correct me, if the input is different:

    static bool Check(string s)
    {
        return s.Contains("ErrorText");
    }

    static void Main(string[] args)
    {
        bool b = Check("00:43:00\nErrorText ");
    }

edit: Ok, I think I got you. What you may want to check are regular expressions (class Regex). You can then check if the passed string has a certain format.

Upvotes: 1

Adrien G.
Adrien G.

Reputation: 431

You have an error. To compare strings in the second condition, you should use the .Equals method, not a '=='. Maybe your error came from here.

Upvotes: 0

Related Questions