In python, how can I print lines that do NOT contain a certain string, rather than print lines which DO contain a certain string:

The problem isn’t your use of not, it’s that or doesn’t mean what you think it does (and if you think it through, it couldn’t): You’re asking whether the expression (“StatusRequest” or “StatusResponse”) appears in line. But that expression is just the same thing as “StatusRequest”. Put it in English: you’re not trying to say “if neither of these is in line”. Python … Read more

Case insensitive ‘Contains(string)’

To test if the string paragraph contains the string word (thanks @QuarterMeister) Where culture is the instance of CultureInfo describing the language that the text is written in. This solution is transparent about the definition of case-insensitivity, which is language dependent. For example, the English language uses the characters I and i for the upper and lower case versions of the ninth letter, whereas the Turkish language uses … Read more

How do I check if a string contains a specific word?

You can use the strpos() function which is used to find the occurrence of one string inside another one: Note that the use of !== false is deliberate (neither != false nor === true will return the desired result); strpos() returns either the offset at which the needle string begins in the haystack string, or the boolean false if the needle isn’t found. Since 0 is a … Read more