

- 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
How to find a substring from a string in C#?
Set the string
string s = "Tom Cruise";
Now let’s say you need to find the substring “Tom”, then use the Contains() method.
if (s.Contains("Tom") == true) { Console.WriteLine("Substring found!"); }
The following is the code to learn how to find a substring from a string −
Example
using System; public class Demo { public static void Main() { string s = "Tom Cruise"; if (s.Contains("Tom") == true) { Console.WriteLine("Substring found!"); } else { Console.WriteLine("Substring not found!"); } } }
Output
Substring found!
- Related Questions & Answers
- How to extract a substring from inside a string in Python?
- How to extract certain substring from a string using Java?
- Removing a specific substring from a string in JavaScript
- How can we extract a substring from a string in MySQL?
- C++ code to find string where trygub is not a substring
- Find if a given string can be represented from a substring by iterating the substring “n” times in C++
- Minimum steps to remove substring 010 from a binary string in C++
- How can we get substring from a string in Python?
- Find if a substring exists within a string in Arduino
- How to find and extract a number from a string in C#?
- How to write unicode regular expressions to find a substring in a string using Python?
- How to find the nth occurrence of substring in a string in Python?
- How to find index of last occurrence of a substring in a string in Python?
- How to check if string or a substring of string starts with substring in Python?
- How to find a matching substring using regular expression in C#?
Advertisements