简体   繁体   English

检查文本是否包含字符串

[英]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?当然这不适用于Contains ,我还能如何处理呢?

Something like Likes: %nExampleText% ? Likes: %nExampleText%类的东西?

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 ).您可能要检查的是正则表达式( class Regex )。 You can then check if the passed string has a certain format.然后,您可以检查传递的字符串是否具有某种格式。

You have an error.你有一个错误。 To compare strings in the second condition, you should use the.Equals method, not a '=='.要比较第二个条件中的字符串,您应该使用 .Equals 方法,而不是 '=='。 Maybe your error came from here.也许你的错误来自这里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM