我想这么做
let mystr = r#"
Id("#1#")
Id("#2#")
Id("#3#")
"#;
它不能编译,因为我需要设法避开"#
和#"
次事件.但我不知道该怎么.
我想这么做
let mystr = r#"
Id("#1#")
Id("#2#")
Id("#3#")
"#;
它不能编译,因为我需要设法避开"#
和#"
次事件.但我不知道该怎么.
因此,您的方法的问题在于您的原始字符串包含用于终止原始字符串的序列.您需要做的是在原始字符串的开始和结束处再添加#
.就像这样:
let mystr = r##"
Id("#1#")
Id("#2#")
Id("#3#")
"##;
Notice second opening and closing #
.
Output is:
Id("#1#")
Id("#2#")
Id("#3#")
你可以在这里的playground上查看.
看看docs个,特别是这一部分:
原始字符串文字不处理任何转义.它们以字符U+0072(R)开头,后跟少于256个字符U+0023(#)和一个U+0022(双引号)字符.The raw string body can contain any sequence of Unicode characters and is terminated only by another U+0022 (double-quote) character, followed by the same number of U+0023 (#) characters that preceded the opening U+0022 (double-quote) character.个