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 the Path to My Documents Folder

C# Finding the Path to the Windows System32 Folder

C# Finding Cosine of an Angle

Splitting a String By Desired Character in C#

C# Linq Contains Method