
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to check if a string contains a certain word in C#?
Use the Contains() method to check if a string contains a word or not.
Set the string −
string s = "Together we can do so much!";
Now let’s say you need to find the word “much”
if (s.Contains("much") == true) { Console.WriteLine("Word found!"); }
Let us see the complete code −
Example
using System; public class Demo { public static void Main() { string s = "Together we can do so much!"; if (s.Contains("much") == true) { Console.WriteLine("Word found!"); } else { Console.WriteLine("Word not found!"); } } }
Output
Word found!
- Related Articles
- MySQL query to check if a string contains a word?
- How to check if a string only contains certain characters in Python?
- How to check if the string contains the specific word?
- Java Program to check if the String contains only certain characters
- How to check if a string contains a specific sub string?
- How to check if a string contains a substring in Golang?
- Check if a string contains a sub-string in C++
- How to check if a Python string contains only digits?
- How to check if a string contains only decimal characters?
- How to check if a string has a certain piece of text in JavaScript?
- Check if a field contains a string in MongoDB?
- Check if a String Contains a Substring in Linux
- Check if a string contains numbers in MySQL?
- How to check if a string contains only whitespace letters in Python?
- How to check if a String contains another String in a case insensitive manner in Java?

Advertisements