How to get the last 4 characters of a string in C#
In this tutorial, we are going to learn about how to get the last 4 characters of a strings in C#.
Using the Substring() method
To access the last 4 characters of a string we can use the
Substring() method by passing the
string.Length-4 as an argument to it.
Here is an example, that gets the last four characters
ople from the following string:
string mystring = "Hellopeople"; string lastFour = mystring.Substring(mystring.Length - 4); Console.WriteLine(lastFour);