rustWhat are the escape sequences for Rust strings?
Rust strings support a variety of escape sequences to represent special characters. The following are the escape sequences for Rust strings:
\n: This is used to represent a new line.
Example code
let s = "Hello\nWorld";
println!("{}", s);
Output example
Hello
World
\t: This is used to represent a tab character.
Example code
let s = "Hello\tWorld";
println!("{}", s);
Output example
Hello World
\r: This is used to represent a carriage return.
Example code
let s = "Hello\rWorld";
println!("{}", s);
Output example
World
\0: This is used to represent the null character.
Example code
let s = "Hello\0World";
println!("{}", s);
Output example
Hello
\\: This is used to represent a backslash character.
Example code
let s = "Hello\\World";
println!("{}", s);
Output example
Hello\World
Helpful links
More of Rust
- How to use regex to match a double quote in Rust?
- How to create a HashMap of structs in Rust?
- How to replace a capture group using Rust regex?
- How to match the end of a line in a Rust regex?
- How to modify an existing entry in a Rust HashMap?
- How do I identify unused variables in Rust?
- How to use negation in Rust regex?
- Regex example to match multiline string in Rust?
- How to use a Rust HashMap in a struct?
- How do I use a variable number of arguments in Rust?
See more codes...