1.

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

Answer»

To GET the last three characters, use the String Substring() method. The parameter to be set under it should be “Length - 3” i.e. the last three characters. A program that obtains the last 3 characters from a string is given as follows:

USING System; public class Demo { public static VOID Main() {     string STR = "This is an example";     string resultStr = str.Substring(str.Length - 3);     Console.WriteLine("Original string: {0}", str);     Console.WriteLine("Resultant string: {0}", resultStr); } }

The output of the above program is as follows:

Original string: This is an example Resultant string: ple


Discussion

No Comment Found