How to get a substring from a string in C# – Programming Code Examples
C# C# Console Application

How to get a substring from a string in C#1 min read

How to get particular text from string in C#

.net String.Substring method allow us to retrieve a substring from a string object. this method have two overloaded method those are Substring(Int32) and Substring(Int32, Int32).




Substring(Int32) overloaded method retrieve a substring from a string by starting at a specified character position and continues to the end of the string. this method need to pass a parameter name startIndex. this parameter data type is System.Int32. startIndex parameter value specify a zero based starting character position of the string. this method does not modify the current string instance, it returns a new string that begins at the startIndex position of the current string.

Substring(Int32, Int32) overloaded method allow us to get a substring from a string that start a specified character position of string and has a specified length. this method have two parameters, those are startIndex and length. startIndex is the zero based starting character position of a substring in this instance. length parameter specify the number of characters in the substring.

the folLowing console c# example code demonstrate us how can we get a substring from a string in .net framework.

C# Code:

Output:

 

Leave a Comment