如何在 C# 中获取字符串中的最后 4 个字符?
首先,设置字符串 -
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
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP