index of c#

index of c#

 

The String.IndexOf() method in C# is used to find the zero-based index of the first occurrence of a specified Unicode character or string within this instance.

 

public int IndexOf(char x)

using System;

class Program
{
    static void Main()
    {
        string value = "cow,dog";

        // Part A: find index of dog.
        Console.WriteLine(value.IndexOf("dog"));

        // Part B: test not found value.
        if (value.IndexOf("emp") == -1)
        {
            Console.WriteLine("?");
        }
    }
}

 

 

2021-10-03