Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

R 转义字符


转义字符

要插入字符串中不允许的字符,必须使用转义字符。

转义字符是一个反斜杠 \ 后跟要插入的字符。

例如,双引号内的双引号就是一个不允许的字符。

示例

str <- "We are the so-called "Vikings", from the north."

str

结果

错误:在 "str <- "We are the so-called "Vikings" 中出现意外符号
自己尝试 »

要解决此问题,请使用转义字符 \"

示例

转义字符允许你在通常不允许的情况下使用双引号。

str <- "We are the so-called \"Vikings\", from the north."

str
cat(str)
自己尝试 »

请注意,自动打印 str 变量将在输出中打印反斜杠。可以使用 cat() 函数打印它,而无需反斜杠。

R 中的其他转义字符

代码 结果
\\ 反斜杠
\n 换行
\r 回车
\t 制表符
\b 退格

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.