Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#相当于python中的rjust_C#_Python - Fatal编程技术网

C#相当于python中的rjust

C#相当于python中的rjust,c#,python,C#,Python,我正在使用python中的rjust来格式化一个表,这在C#中是如何实现的 它应该输出如下内容: Interpret: +---+---+---+---+---+---+---+ Interpret: | 0 Example | Interpret: +---+---+---+---+---+---+---+ 试试这个 static void Main(string[] args) { string s = "Interp

我正在使用python中的rjust来格式化一个表,这在C#中是如何实现的

它应该输出如下内容:

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是您的字符串。

没有相同的效果。您能解释一下原因吗?两者都有相同的行为
Console.WriteLine($"Interpret: |   0 {"Example",14} {'|',9}");