C# C# Console

How to Check if a Substring is Present in a Given String in C#

C# program to check if a Substring is present in a Given String.

Use the contains() method in C# to check if a substring is in a given string.

Let us say the string is −

Within the string, you need to find the substring “Uni”. For that, use the contains method and use it like the following code snippet −

Example

You can try to run the following code to find a substring in a string.

Output:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.