如何在 Rust 中编写多行字符串? [英] How do I write a multi-line string in Rust?

查看:42
本文介绍了如何在 Rust 中编写多行字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以写成这样:

fn main() {
    let my_string: &str = "Testing for new lines \
                           might work like this?";
}

推荐答案

如果我正在阅读 语言参考 正确,然后看起来应该可以工作.语言参考声明支持 \n 等(作为常见转义,用于在字符串中插入换行符),以及附加转义",包括 LF、CR 和 HT.

If I'm reading the language reference correctly, then it looks like that should work. The language ref states that \n etc. are supported (as common escapes, for inserting line breaks into your string), along with "additional escapes" including LF, CR, and HT.

这篇关于如何在 Rust 中编写多行字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆