在 C# 中进行 String Formatting 来添加右部填充
要为 String 添加右填充 -
const string format = "{0,10}";现在将它添加到 String -
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP