In this source code example, we will demonstrate the usage of String.IndexOf() method in C# with an example.
The C# String.IndexOf() is used to get an index of the specified character present in the string. It returns the index as an integer value.
C# String IndexOf Method Example
The following example demonstrates the use of the String.IndexOf() method:
using System;
public class StringDemo
{
public static void Main(string[] args)
{
string s1 = "sourcecodeexamples";
// IndexOf returns the location of the string "exmples" It is located at index 10.
int result = s1.IndexOf("examples");
Console.WriteLine(result);
// search a String for a character using the IndexOf method.
int result1 = s1.IndexOf('o');
Console.WriteLine(result1);
}
}
Output:
10
1
Related C# String Examples
- C# String Clone Method Example
- C# String Compare Method Example
- C# String CompareTo Method Example
- C# String Concat Method Example
- C# String Contains Method Example
- C# String Copy Method Example
- C# String CopyTo Method Example
- C# String EndsWith Method Example
- C# String Equals Method Example
- C# String GetEnumerator Method Example
- C# String GetHashCode Method Example
- C# String IndexOf Method Example
- C# String Insert Method Example
- C# String Intern Method Example
- C# String IsNullOrEmpty Method Example
- C# String IsNullOrWhiteSpace Method Example
- C# String LastIndexOf Method Example
- C# String Clone Method Example
- C# String Compare Method Example
- C# String CompareTo Method Example
- C# String Concat Method Example
- C# String Contains Method Example
- C# String Copy Method Example
- C# String CopyTo Method Example
- C# String EndsWith Method Example
- C# String Equals Method Example
- C# String GetEnumerator Method Example
- C# String GetHashCode Method Example
- C# String IndexOf Method Example
- C# String Insert Method Example
- C# String Intern Method Example
- C# String IsNullOrEmpty Method Example
- C# String IsNullOrWhiteSpace Method Example
- C# String LastIndexOf Method Example
Comments
Post a Comment