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 97 views
1 answer 133 views
2 answers 189 views
2 answers 201 views
3 answers 185 views
1 answer 118 views
1 answer 118 views
...