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# Finding Cosine of an Angle

Finding the Index Order of a Character in a String in C#

Splitting a String By Desired Character in C#

C# Taking Action by MessageBox OK Button

C# Non-Restart Check If Application is Open