格式很好的文本文件
我正在写一个文本文件,它看起来像这样……
19/05/2010 15:33:34 Verbose Main in main method 19/05/2010 15:33:34 Information DoesSomethingInteresting() the answer to faster than light travel is
但我希望它看起来像是……
19/05/2010 15:33:34 Verbose Main in main method 19/05/2010 15:33:34 Information DoesSomethingInteresting() the answer to faster than light travel is
你知道,所以它的格式和标签对齐都很好。 有没有一种简单的方法可以做到这一点,运行时的某些function将处理所有繁琐的填充?
这是我编写的代码
LogFile.Write(string.Format("{0}t{1}t{2}t{3}", log.Time, log.Level, log.Method, log.Message));
要将字符串与左对齐,请使用逗号(,)后跟负数字符的格式化模式:
LogFile.Write(string.Format("{0,-10} {1,-11} {2,-30} {3}", ...));
对于右对齐,请使用正数。
上述就是C#学习教程:格式很好的文本文件分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。
如若转载,请注明出处:https://www.ctvol.com/cdevelopment/1042094.html