How to get the last 3 characters from a string in C#

1 Answer

0 votes
using System;
  
class Program
{
    static void Main() {
        string s = "csharp programming";
          
        string last_3_chars = s.Substring(Math.Max(0, s.Length - 3)); 
  
        Console.Write(last_3_chars);
    }
}
  
  
 
  
/*
run:
  
ing
  
*/

 



answered Aug 6, 2023 by avibootz

Related questions

1 answer 114 views
1 answer 147 views
2 answers 204 views
2 answers 222 views
3 answers 205 views
1 answer 130 views
1 answer 128 views
...