1

我需要创建一个控制台应用程序来打印一些帮助消息。我已经这样做了,但它没有在控制台中以默认表格格式显示结果,例如,

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.

我需要使用转义序列还是有任何内置功能可以像这样显示。我用谷歌搜索了它。但是找不到解决方案,任何人都可以帮助:)?

4

4 回答 4

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);
于 2012-09-27T09:55:10.983 回答
1

您可能想为此使用复合格式

于 2012-09-27T09:45:58.237 回答
1

在这种非常特殊的情况下,只需将内容放在文本文件中,然后将文本文件的内容写入控制台流。

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

于 2012-09-27T09:48:01.283 回答
0

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

Console.WriteLine("DIR [drive:][path][filename] [/A[[:]attributes]]");
Console.WriteLine("  [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]]");
于 2012-09-27T09:45:52.727 回答