My issue
My code
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
string txt = "Please find chef";
Console.WriteLine( txt.IndexOf("ease") );
Console.WriteLine(txt.IndexOf("chef"));
}
}
}
Learning course: Learn C#
Problem Link: CodeChef: Practical coding for everyone
In the first Console.WriteLine()
statement, txt.IndexOf("ease")
is called. This method searches for the substring “ease” within the string txt
. Since the substring “ease” is found starting at index 2 (considering zero-based indexing), the output will be 2
.
In the second Console.WriteLine()
statement, txt.IndexOf("chef")
is called. This method searches for the substring “chef” within the string txt
. The substring “chef” is found starting at index 12, the output will be 12
.