การเพิ่มช่องว่างด้านขวาให้กับสตริง −
const string format = "{0,10}"; ตอนนี้เพิ่มลงในสตริง −
string str1 = string.Format(format, "Marks","Subject");
ให้เราดูรหัสที่สมบูรณ์ -
ตัวอย่าง
using System;
public class Program {
public static void Main() {
// set right padding
const string format = "{0,10}";
string str1 = string.Format(format, "Marks","Subject");
string str2 = string.Format(format, "95","Maths");
Console.WriteLine(str1);
Console.WriteLine(str2);
}
} ผลลัพธ์
Marks 95