[c#] Get last 3 characters of string

How can I get only the last 3 character out from a given string?

Example input: AM0122200204

Expected result: 204

This question is related to c#

The answer is


The easiest way would be using Substring

string str = "AM0122200204";
string substr = str.Substring(str.Length - 3);

Using the overload with one int as I put would get the substring of a string, starting from the index int. In your case being str.Length - 3, since you want to get the last three chars.