C# 相当于 python 中的 rjust
本文关键字:rjust 中的 python 相当于 | 更新日期: 2023-09-27 18:32:41
我在python中使用rjust来格式化表格,如何在C#中完成此操作?
print 'Interpret: +---+---+---+---+---+---+---+'
print 'Interpret: | 0 ' + 'Example'.rjust(14) + '|'.rjust(9)
print 'Interpret: +---+---+---+---+---+---+---+'
它应该输出如下内容:
Interpret: +---+---+---+---+---+---+---+
Interpret: | 0 Example |
Interpret: +---+---+---+---+---+---+---+
试试这个
static void Main(string[] args)
{
string s = "Interpret: | 0 " + "Example".PadLeft(14) + "|".PadLeft(9);
Console.WriteLine(s);
}
我会使用字符串格式。
Console.WriteLine($"Interpret: | 0 {"Example",14} {'|',9}");
如果我理解正确,请尝试使用 x.PadLeft(9+x.Length),其中 x 是你的字符串。