C#用换行符编码文本字符串 [英] C# Encoding a text string with line breaks

查看:154
本文介绍了C#用换行符编码文本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中我有一个字符串我正在写回响应的输出流。在我保存此文档并在Notepad ++或写字板中打开它之后,我会得到很好的格式化的换行符,当我打开这个文件与常规的旧Windows记事本时,我得到一个长文本字符串[]方形符号,其中的行休息应该是。



有没有人有这方面的经验?



谢谢



Jim

解决方案是的 - 这意味着你使用 \\\
作为换行符,而不是 \r\\\
。记事本只能理解后者。



(请注意,其他人建议的 Environment.NewLine 如果您希望平台默认 - 但是如果您从Mono服务,并且肯定需要 \r\\\
,则应明确指定。)


in C# I have a string I am writing to the outputstream of the response. After I save this document and open it in Notepad++ or WordPad I get nicely formatted line breaks where they are intended, when I open this document with the regular old windows notepad, I get one long text string with [] square looking symbols where the line breaks should be.

Has anyone had any experience with this?

Thanks

Jim

解决方案

Yes - it means you're using \n as the line break instead of \r\n. Notepad only understands the latter.

(Note that Environment.NewLine suggested by others is fine if you want the platform default - but if you're serving from Mono and definitely want \r\n, you should specify it explicitly.)

这篇关于C#用换行符编码文本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆