C# Substrings

In this article we will discuss about how to work with substrings in C#.
  • 3350

A substring is a part of a string. The Substring method retrieves a substring from a string starting at a specified position. The Substring method has two overloaded forms. The first form takes just an integer as the starting position of the substring and returns rest of the string. The second form takes first integer as the starting position and second integer as the length of the substring.

The following code snippet gets two substrings from a string.

string sentence = "Mahesh Chand is an author and founder of C# Corner";
Console
.WriteLine("Original String: {0}", sentence);
Console.WriteLine("Substring starting at 20: {0}", sentence.Substring(20));
Console.WriteLine("Substring starting at 20, next 10 chars: {0}", sentence.Substring(20, 10));   


Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.