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