如何从 Visual Studio C#.net 创建文本文件 (.txt) 并禁用自动换行?
实际上我正在维护一个日志文件,其中一些值以表格形式存储,但表格内容超出了行限制,我希望表格值显示在一行中。
有什么办法吗?
非常感谢您的回复!
问候
最佳答案
您将记事本中的 Word Wrap 与字符串混淆了。您从 C# 添加到 txt 文件中的字符串未换行。如果 WordWrap 打开,在记事本中看到它可能会换行。
存储在 txt 文件中的字符串永远不会自行换行..(你没有任何换行字符,只有\n 用于换行)。
自动换行是任何文本编辑器的一项功能,它与实际字符串(文本)无关。以下是维基百科关于其含义的摘录。
In text display, line wrap is the feature of continuing on a new line when a line is full, such that each line fits in the viewable window, allowing text to be read from top to bottom without any horizontal scrolling. Word wrap is the additional feature of most text editors, word processors, and web browsers, of breaking lines between and not within words, except when a single wordis longer than a line.
如果您不想包装文本,请在编辑器中禁用它(如 Notpad)。您不能在 String(Text) 本身中做任何事情(如果需要,除了在一定数量的单词之后添加
\n
之外)。
关于c# - 如何从 Visual Studio C#.net 创建一个文本文件 (.txt) 与自动换行属性禁用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4919683/