Để thêm phần đệm ở bên phải vào một chuỗi -
const string format = "{0,10}"; Bây giờ hãy thêm nó vào chuỗi -
string str1 = string.Format(format, "Marks","Subject");
Hãy cho chúng tôi xem mã hoàn chỉnh -
Ví dụ
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);
}
} Đầu ra
Marks 95