
- 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
C# program to find the index of a word in a string
Declare and initialize an array −
string[] str = new string[] { "Cat", "Mat", "Rat" };
Now, ue IndexOf() method to find the index of the word “Mat” −
Array.IndexOf(str, "Mat");
The following is the code −
Example
using System; public class Demo { public static void Main() { string[] str = new string[] { "Cat", "Mat", "Rat" }; Console.WriteLine("Our Array ="); for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); } int findIndex = Array.IndexOf(str, "Mat"); Console.Write("Element Mat found at the following index: "); Console.WriteLine(findIndex); } }
Output
Our Array = Cat Mat Rat Element Mat found at the following index: 1
- Related Articles
- Program to find Smallest and Largest Word in a String in C++
- C# program to count occurrences of a word in string
- How to find a replace a word in a string in C#?
- Find frequency of each word in a string in C#
- Find the first repeated word in a string in C++
- Find last index of a character in a string in C++
- Python program to count occurrences of a word in a string
- Java program to count occurrences of a word in string
- How to find the Index of a string in Golang?
- C# program to find the index of an element in a List
- PHP program to find the length of the last word in the string
- Write a python program to count occurrences of a word in string?
- Golang Program to get the index of the substring in a string
- Python Program to get the index of the substring in a string
- Program to find out the letter at a particular index in a synthesized string in python

Advertisements