有没有办法逃脱字符串中的换行符?我尝试将代码行打破大约80个字符,但有时我会编写比这些行更长的消息。有没有办法逃脱换行?我不想将多个字符串粘贴到一个字符串中。
cat(sprintf(
'%s Re-quantify was set to "True"! Please reanalyse data with correct settings and start the script again.\n',
date()))
如果我添加新行,则该消息也会以两行打印
cat(sprintf(
'%s Re-quantify was set to "True"! Please reanalyse data
with correct settings and start the script again.\n',
date()))
我知道paste
解决了我的问题,但我认为代码更难阅读。
cat(sprintf(
paste('%s Re-quantify was set to "True"! Please reanalyse data',
'with correct settings and start the script again.\n'),
date()))
那么我可以做内联吗?只使用\
来逃避换行符不起作用。
答案 0 :(得分:2)
也许不是最优雅的解决方案,但它确实有效。您可以使用退格键启动新行:
cat(sprintf(
'%s Re-quantify was set to "True"! Please reanalyse data
\b with correct settings and start the script again.\n',
date()))
这只会删除输出中的新行。
您还可以从cat
接受多个参数并将它们与空格组合作为分隔符的事实中获益:
cat(sprintf('%s', date()),
'Re-quantify was set to "True"! Please reanalyse data',
'with correct settings and start the script again.\n')