奈斯利格式的文本文件 [英] Nicely formatted text file
本文介绍了奈斯利格式的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在写一个文本文件,它看起来像这样...
19/05/2010 15时33分34秒详细主要的主要方法
19/05/2010 15时33分34秒信息DoesSomethingInteresting()答案比光速是
块引用>但我想它看起来就像是...
19/05/2010 15时33分34秒详细主要的主要方法
19/05/2010 15时33分34秒信息DoesSomethingInteresting()答案比光速是
块引用>您知道,所以这一切都很好地格式化和标签一致。有一个简单的方法来做到这一点,在运行时的一些函数,将处理所有繁琐的填充?
下面是我的code,做了写
LogFile.Write(的String.Format({0} \\ t {1} \\ t {2} \\ t {3},log.Time,log.Level,日志。方法,log.Message));
解决方案要对齐一个字符串,使用左侧的格式与逗号模式(,),其次是负数字符:
LogFile.Write(的String.Format({0,-10} {1,-11} {2,-30} {3},...));
有关右对齐使用一个正数。
I’m writing to a text file and it looks like this...
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
But what i’d like it to look like 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
You know, so it's all nicely formatted and tabbed aligned. Is there an easy way to do this, some function in the runtime that will deal with all the tedious padding?
Here is my code that does the writing
LogFile.Write(string.Format("{0}\t{1}\t{2}\t{3}", log.Time, log.Level, log.Method, log.Message));
解决方案To align a string to the left use formatting pattern with comma (,) followed by a negative number of characters:
LogFile.Write(string.Format("{0,-10} {1,-11} {2,-30} {3}", ...));
For right alignment use a positive number.
这篇关于奈斯利格式的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文