问题描述
在Python中,可以写入 ra\\\
,以防止
b \\\
被解释为转义序列的换行符。
In Python one can write r"a\nb"
in order to prevent the \n
from being interpreted as an escape sequence for newline.
在Julia有类似的东西吗?而如果像$ variable
这样的字符串插入怎么办?有没有办法阻止它?
Is there something similar in Julia? And what about string interpolation like "$variable"
, is there a way to prevent it?
我知道一个可以在Julia中写下a\\
和
b\ $ variable
喜欢写很多LaTeX字符串,而不必关心每个反斜杠 \
和美元 $
字符的正确转义。
I know one can simply write "a\\nb"
and "\$variable"
in Julia, but I would like to write a lot of LaTeX strings without having to care to proper escape every backslash \
and dollar $
characters...
(在Julia, r...
创建一个正则表达式。)
(In Julia, r"..."
creates a regular expression.)
推荐答案
好的,我刚刚发现,由于可以轻松创建,我将要求的是:
Ok, I just found out that since one can easily create non-standard string literals in Julia, a pass-through one will do what I was asking for:
macro R_str(s)
s
end
>>> R"$a\n$b"
"\$a\\n\$b"
>>> print(R"$a\n$b")
$a\n$b
我还发现定义了一个类型,可以通过 L....
没有转义反斜杠或美元符号»,另外有益于在IJulia提出的方程式。
I also discovered that PyPlot.jl defines a «LaTeXString type which can be constructed via L"...."
without escaping backslashes or dollar signs», with the additional benefit of rendered equations in IJulia.
最后一个问题是:不值得拥有一个原始的在朱莉娅基地的字符串字面量?
A last question remains: is not worth it to have a raw string literal in Julia base?
这篇关于在朱莉娅的原始文字字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!