rustHow do you create a multi-line string in Rust?
Creating a multi-line string in Rust is done using a raw string literal. A raw string literal is a string that is surrounded by two backslashes (\) and a pair of double quotes ("). The backslashes tell the compiler to ignore any special characters within the string.
Example code
let my_string = r"This is a
multi-line string
in Rust";
Output example
This is a
multi-line string
in Rust
Code explanation
let: This is a keyword used to declare a variable.my_string: This is the name of the variable.r: This is a prefix used to indicate a raw string literal.": This is a double quote used to enclose the string.\: This is a backslash used to indicate that the compiler should ignore any special characters within the string.
Helpful links
More of Rust
- How to replace a capture group using Rust regex?
- How to use Unicode in a regex in Rust?
- How to replace strings using Rust regex?
- Regex example to match multiline string in Rust?
- How to split a string with Rust regex?
- How to match the end of a line in a Rust regex?
- How to use regex with bytes in Rust?
- How to match whitespace with a regex in Rust?
- How to match a URL with a regex in Rust?
- How to use non-capturing groups in Rust regex?
See more codes...