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 96 views
1 answer 132 views
2 answers 188 views
2 answers 199 views
3 answers 183 views
1 answer 116 views
1 answer 116 views
...