I have the following code where frequencyOfReminders = "2 days"
dailyReminders = frequencyOfReminders.IndexOf("day", StringComparison.OrdinalIgnoreCase) >= 0;
I want dailyReminders to be true should I use the below instead?
dailyReminders = frequencyOfReminders.Contains("day", StringComparison.OrdinalIgnoreCase) >= 0;
I should have been clearer. I have the string frequencyOfReminders= “2 days” for eg
and I want dailyreminders to return true if it finds the string “day” in frequencyOfReminders, other values where it would return true are : daily, 3 days, 1 day, … etc
The String.Contains method returns a boolean, so the >= 0 won’t compile.
Should be like this:
However, in this case I would lean towards Contains for readability.
Edit:
Oh, you’re searching for multiple search terms. In that case, one way to do it is with multiple Contains calls (straightforward):
Another way is to get into regular expressions (fully explaining this approach will take some work), but here is a link that explains it:
http://www.regular-expressions.info/dotnet.html
Regular expressions are incredibly powerful, but there is a learning curve.