如何在 C# 中找到字串的第一個字元?
要獲取第一個字元,可以使用 substring() 方法。
假設以下內容是我們的字串 −
string str = "Welcome to the Planet!";
現在,要獲取第一個字元,請在 substring() 方法中設定值 1。
string res = str.Substring(0, 1);
讓我們看看完整的程式碼 −
示例
using System; public class Demo { public static void Main() { string str = "Welcome to the Planet!"; string res = str.Substring(0, 1); Console.WriteLine(res); } }
輸出
W
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP