2012-09-27 69 views
1

我需要创建一个控制台应用程序来打印一些帮助messages.I已经做到了,但它并没有显示在控制台就像默认的表格格式的结果,需要得到格式化输出C#

c:\Users\>dir /? 
Displays a list of files and subdirectories in a directory. 

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] 
    [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4] 

    [drive:][path][filename] 
       Specifies drive, directory, and/or files to list. 

    /A   Displays files with specified attributes. 
    attributes D Directories    R Read-only files 
       H Hidden files    A Files ready for archiving 
       S System files    I Not content indexed files 
       L Reparse Points    - Prefix meaning not 
    /B   Uses bare format (no heading information or summary). 
    /C   Display the thousand separator in file sizes. This is the 
       default. Use /-C to disable display of separator. 
    /D   Same as wide but files are list sorted by column. 
    /L   Uses lowercase. 
    /N   New long list format where filenames are on the far right. 
    /O   List by files in sorted order. 
    sortorder N By name (alphabetic)  S By size (smallest first) 
       E By extension (alphabetic) D By date/time (oldest first) 
       G Group directories first - Prefix to reverse order 
    /P   Pauses after each screenful of information. 

待办事项我需要使用转义序列或有任何内置函数来显示这样的。我GOOGLE了它。但无法找到解决方案可以帮助任何人:)?

回答

0

只需使用空格来格式化输出。

Console.WriteLine("DIR [drive:][path][filename] [/A[[:]attributes]]"); 
Console.WriteLine(" [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]]"); 
1

在这个非常特殊的情况下,只需将内容放在文本文件中,并向控制台写入文本文件的内容即可。

我会将文本文件作为资源来简化部署。

1

您应该必须使用@-quoted字符串文字。

string help = @" 
Usage of @-quoted literal: 
    1. Escape sequences are not processed 
    2. To include double quotes then ""double it"" 
"; 
Console.WriteLine(help);