C# 像 Rust 中的逐字字符串?

C# like verbatim string in Rust?

我正在寻找 Rust 中的逐字字符串(就像在 C# 中使用 @"This is a string and here ""I am between quotes without making a fuss""")。

有类似的吗?

我猜raw string literals你在找什么?

 let raw_string_literal = r#" line1 \n still line 1"#;
 println!("{}", raw_string_literal);

This出奇的难找。

在 rust 中,原始字符串文字被 r"" 包围,如果需要使用引号,请添加 #。 对于你的例子,
r#"This is a string and here "I am between quotes without making a fuss""#
应该可以。 (双引号会在字符串中产生双引号。)

如果你需要带有 # 符号的东西,你可以这样做
r###"This string can have ## in as many places as I like ##, but never three in a row ##"###

但是,在生锈的原始字符串中,转义是不允许的。例如,您不能使用 \n。但是,您可以包含任何您想要的 UTF-8 字符。