写一个“\ n”在一个文本文件中 [英] Writing a "\n" in a text file

查看:254
本文介绍了写一个“\ n”在一个文本文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在文本文件中写入一个字符串\ n。但是在文本文件中的结果是一个换行符。我知道\\\
代表一个换行符。但在我的情况下,我真的需要看到字符串\\\
,而不是换行符。如何解决这个问题?

解决方案

<\\ p> \字符转义下一个字符,就像\ n会创建一个换行符。如果你想输出一个实际的\,你需要写:

 \\

通过这种方式,第一个斜杠可以转义第二个斜杠,生成一个实际的斜线而不是转义n。 b $ b

I'm trying to write a string \n in a text file. But the result in the text file is a newline. I know that the \n represents a newline. But in my case, I really need to see the String \n, not the newline. How can I solve this?

解决方案

The \ character escapes the next character, as you say \n will create a newline. If you wish to output an actual \, you need to write:

"\\n"

That way the first slash escapes the second slash, generating an actual slash rather than escaping the n.

这篇关于写一个“\ n”在一个文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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