要在字符串右边添加填充-
const string format = "{0,10}";
现在将其添加到字符串-
string str1 = string.Format(format, "Marks","Subject");
让我们看完整的代码-
using System; public class Program { public static void Main() { //设置右填充 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