contains substring in csharp

To check if a string contains a substring in C#, you can use the Contains() method. Here's an example:

string str = "Hello World";
if (str.Contains("World"))
{
    Console.WriteLine("Substring found!");
}
102 chars
6 lines

In this example, we're checking if the string str contains the substring "World". If it does, we'll print "Substring found!" to the console. Otherwise, we'll skip the message.

related categories

gistlibby LogSnag