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.


Are you a .NET Developer planning to integrate GraphQL for .NET in your Application? Check out this book BUY & DOWNLOAD GRAPHQL.NET COOKBOOK

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);
    }
}
%d bloggers like this: