
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
United
Within the string, you need to find the substring “Uni”. For that, use the contains method and use it like the following code snippet −
res = str1.Contains(str2);
Example
You can try to run the following code to find a substring in a string.
using System; public class Demo { public static void Main() { string str1 = "United", str2 = "Uni"; bool res; res = str1.Contains(str2); if (res) Console.Write("The substring " + str2 + " is in the string " + str1); else Console.Write("The substring " + str2 + " is not in the string " + str1); } }
Output
The substring Uni is in the string United
- Related Questions & Answers
- Python Program to check if a substring is present in a given string.
- Java program to check if a Substring is present in a given String
- Check if substring present in string in Python
- C Program to Check if a Given String is a Palindrome?
- Java Program to Check if a string contains a substring
- Check if a given string is sum-string in C++
- C program to check if a given string is Keyword or not?
- Check if a given string is a valid number in C++
- Python program to check if a given string is number Palindrome
- TCP Client-Server Program to Check if a Given String is a Palindrome
- Python Program to check if a string starts with a substring using regex
- Python program to check if a given string is Keyword or not
- Check if a given string is a rotation of a palindrome in C++
- How to check if a string contains a substring in Golang?
- PHP program to check if a given number is present in an infinite series or not
Advertisements