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

C# Finding the Sine of an Angle

Finding Character Count of String in C#

How to Find the Name of the Operating System in C# ?

Splitting a String By Desired Character in C#