How do I get the last four characters from a string in C#?

mystring.Substring(Math.Max(0, mystring.Length - 4)); //how many lines is this?

If you’re positive the length of your string is at least 4, then it’s even shorter:

mystring.Substring(mystring.Length - 4);

Leave a Comment