How to get last four characters from a string in C#?


This content was proof-read by Grammarly. You can Try Grammary for FREE

This post will provide a simple tip showing how you can get the last 4 characters from a string in C#.

How to get last four characters from a string in C#?

Assume that you have a string that contains the value “CodersEditor.com” and you wish to get .com from the string and display it.

Below is a sample code snippet demonstrating how you can do it.

public class Hello {
    public static void Main() {
        string website = "coderseditor.com";
        string result = website.Substring(website.Length - 4);;
        System.Console.WriteLine(result);
    }
}
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: