วางจุดเริ่มต้นของสตริงด้วยช่องว่างโดยใช้วิธี PadLeft() คุณยังสามารถใส่อักขระ Unicode ลงไปได้
สมมติว่าต่อไปนี้คือสตริงของเรา
string myStr = "DemoOne";
หากต้องการตั้งค่าการเติมที่จุดเริ่มต้นของสตริงข้างต้น ให้ใช้เมธอด PadLeft
myStr.PadLeft(10);
นี่คือตัวอย่างที่สมบูรณ์
ตัวอย่าง
using System;
class Demo {
static void Main() {
string myStr = "DemoOne";
// set padding at the beginning
Console.WriteLine(myStr.PadLeft(10));
myStr = "DemoTWO";
// set padding at the beginning
Console.Write(myStr.PadLeft(15));
}
} ผลลัพธ์
DemoOne DemoTWO