zoukankan      html  css  js  c++  java
  • C#输出文字对齐,空格位数对齐

    Align String with Space

    This example shows how to align strings with spaces. The example formats text to table and writes it to console output.

    To align string to the right or to the left use static method String.Format. To align string to the left (spaces on the right) use formatting patern with comma (,) followed by a negative number of characters: String.Format(„{0,–10}“, text). To right alignment use a positive number: {0,10}.

    Following example shows how to format text to the table. Values in the first and second column are aligned to the left and the third column is aligned to the right.

    [C#]

    Console.WriteLine("-------------------------------");
    Console.WriteLine("First Name | Last Name  |   Age");
    Console.WriteLine("-------------------------------");
    Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Bill", "Gates", 51));
    Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Edna", "Parker", 114));
    Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Johnny", "Depp", 44));
    Console.WriteLine("-------------------------------");
    
    

    Output string:

     -------------------------------
     First Name | Last Name  |   Age
     -------------------------------
     Bill       | Gates      |    51
     Edna       | Parker     |   114
     Johnny     | Depp       |    44
     -------------------------------
  • 相关阅读:
    PHP0002:PHP基础1
    NodeJS_0001:关于install的方式
    JN_0018:运行窗口不显示
    事务、事务操作、事务隔离级别
    MySQL 常见的两种存储引擎
    8:二叉树的下一个节点
    链表
    文件压缩
    MapReduce--Shuffle原理
    volatile关键字
  • 原文地址:https://www.cnblogs.com/coolsundy/p/5863200.html
Copyright © 2011-2022 走看看