C# Substring Method

Substring method is used to get a desired part from a string.

It has 2 ways of use.

In its first use, the starting index is given and the number of characters to be taken from here is specified.

namespace ConsoleApplicationTest
{
    class Program
    {
        static void Main(string[] args)
        {

            string sub = "test string";
            string result = sub.Substring(0, 3);

        }
    }
}

The result here is "tes".

In the second use, only the starting index is given. All characters after the specified value are taken.

namespace ConsoleApplicationTest
{
    class Program
    {
        static void Main(string[] args)
        {

            string sub = "test string";
            string result = sub.Substring(3);

        }
    }
}

The result here is "t string".



You May Interest

C# Reverse Array

C# Finding the Path to the Windows System32 Folder

Finding Character Count of String in C#

C# Taking Action by MessageBox OK Button

C# Getting Current Time