How to get last 4 characters from string in\\nC#?



Firstly, set the string −

string str = "Football and Tennis";

Now, use the substring() method to get the last 4 characters −

str.Substring(str.Length - 4);

Let us see the complete code −

Example

 Live Demo

using System; public class Demo {    public static void Main() {       string str = "Football and Tennis";       string res = str.Substring(str.Length - 4);       Console.WriteLine(res);    } }

Output

nnis
Updated on: 2020-06-22T12:19:58+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements