2012-09-27 107 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);