Given a string and we have to get the substring of N characters.
For Example: Input string is "India is great country" and we want to extract the substring (5 characters ) from 9th index, which will be "great".
String.Substring()
String.Substring() Method returns the given number of characters (length) from given starting position (index).
Syntax:
String String.Substring(int index, int length );
Here,
index – is the starting indexing from where you want to extract the substring (indexing starts from 0).
length – is the total number of characters to be extracted.
Return type String – method will return the length characters from index (substring), which will be the result.
Consider the program:
Output