有没有办法在字符串中转义换行符?我尝试将代码行断开到大约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()))那么有什么我可以内联做的吗?仅仅使用\转义换行符是行不通的。
发布于 2016-04-14 03:03:27
也许不是最优雅的解决方案,但它是有效的。您可以在新行开始时使用退格键:
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')https://stackoverflow.com/questions/36601309
复制相似问题