Facebook Page Twitter Page LinkedIn Page
× C# Tutorial C# Advanced C# Resources

The C# string Substring() method is used to retrieve a substring from the given string. The substring starts at the specified index and continues to the end of the string or has a specified length.

Note: This method can be overloaded by passing different type of arguments to it.


public string Substring (int startIndex);
public string Substring (int startIndex, int length);


startIndex Specify the start index of the substring in the given string.
length Specify the length of the substring.

Return Value

Returns the substring from the given string.


throws ArgumentOutOfRangeException, if the startIndex or length indicates a position which is not in the string.


In the below example, Substring() method to used to retrieve a substring from the given string called MyStr.

using System;

class MyProgram {
  static void Main(string[] args) {
    string MyStr = "Hello World";

The output of the above code will be:

Hello Worl

❮ C# String Methods