首先,设置字符串-
string str = "Football and Tennis";
现在,使用该substring()方法获取最后4个字符-
str.Substring(str.Length - 4);
让我们看完整的代码-
using System;
public class Demo {
public static void Main() {
string str = "Football and Tennis";
string res = str.Substring(str.Length - 4);
Console.WriteLine(res);
}
}输出结果
nnis