This post will discuss how to determine whether a string contains a specific substring in C#.

You can use the String.Contains() method, which returns a boolean value indicating whether the specified substring occurs within the string. The following example demonstrates its usage.

Download  Run Code

 
The String.Contains() method performs a case-sensitive comparison. To perform the culture-insensitive comparison, you can directly call the Contains(String, StringComparison) overload instead.

Download  Run Code

 
Alternatively, you can call ToLower() or ToUpper() method before making case-insensitive searches, as shown below.

Download  Run Code

That’s all about determining whether a string contains a specific substring in C#.