What is the use of C# substring?
Substring is used for getting a portion of a string present in the source string.
Substring used for extracting a portion of a string from a given position.
Using substring we can extract a string from a predefined start position to predefined end position.
All the above options are correct.
string s1 = "skill gun";
//code for retrieving second character to 6 th character
string s2=s1.Substring(1, 4);
Note: we used 1 in the first parameter since string is a character array and whose index is starting with 0 . hence index 1 means second character . we used 4 as second parameter since we need total characters 4 in the output i.e from 2nd character to 6th character ( total 4 characters ).
Back To Top