Introduction:

In this article we will explain how to use string substring method or what is string substring method in c# with example.

Description:

In c# programming language substring() method is a string method, the Substring method is used to get a substring from the given string. The substring starts from the specified character position and continues to the end of string.  

C# Substring Method Example

Following is the example of using Substring() method to get a substring starting from the given string in c# programming language.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace SQLTutorialsPoint
{
    class Program
    {
        static void Main(string[] args)
        {
            string msg = "Welcome to SQL Tutorials Poit";
            Console.WriteLine("SubString:{0}",msg.Substring(5));
            Console.WriteLine("Substring with Length: {0}",msg.Substring(3, 7));
            Console.WriteLine("\nPress Enter Key to Exit..");
            Console.ReadLine();
        }
    }
}

 

As you see above example, we used a Substring() method to get a substring starting from the position 5 till the end of defined string and another substring starting from the position 3 and the length of substring should be 7 characters.

 

When we execute above c# program, we will get the result like as shown below.


 How to use String Substring Method in C# with Example

 

As you see above result, the Substring() method has return a required substrings with or without specified length based on our requirements.

 

In this article we have learned, how we can use Substring() method to get a required substrings from then given string starting from the defined position in c# programming language.

 

I hope it will help to you after reading.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like