Use the Contains() method to check if a string contains a word or not.
Set the string −
string s = "Together we can do so much!";
Now let’s say you need to find the word “much”
if (s.Contains("much") == true) {
Console.WriteLine("Word found!");
}Let us see the complete code −
Example
using System;
public class Demo {
public static void Main() {
string s = "Together we can do so much!";
if (s.Contains("much") == true) {
Console.WriteLine("Word found!");
} else {
Console.WriteLine("Word not found!");
}
}
}Output
Word found!