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 Tangent of an Angle

C# Getting Today's Date

C# Finding the Sine of an Angle

C# Finding Cosine of an Angle

C# Linq Contains Method