ในการรับอักขระตัวแรก ให้ใช้เมธอด substring()
สมมติว่าสตริง isour ต่อไปนี้ −
string str = "Welcome to the Planet!";
ในการรับอักขระตัวแรก ให้ตั้งค่าเป็น 1 ในเมธอด substring()
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