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 use regex to match a double quote in Rust?
- How to use regex lookahead in Rust?
- How to use regex to match a group in Rust?
- How to get a capture group using Rust regex?
- How to use backslash in regex in Rust?
- How to parse JSON string in Rust?
- How to replace a capture group using Rust regex?
- How to use non-capturing groups in Rust regex?
- How to make regex case insensitive in Rust?
- How to convert a Rust HashMap to a BTreeMap?
See more codes...