Get substring from a string in C#
To get substring from a string in C# we use Substring method. This method has two overloads.
First takes starting index from where to start extracting substring.
Seconds takes start index and length of string to extract.
stringFruit = "Orange";
stringSubstr = Fruit.Substring(2); //Starts getting substring from Index 2
stringSubstr1 = Fruit.Substring(2, 2); //Starts getting substring from Index 2 and gets only two characters
Console.WriteLine(Substr);
Console.WriteLine(Substr1);
Output
“ange”
“an”
Comments
Post a Comment