如何在 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