rustAppend string in Rust
String concatenation in Rust can be done using the +
operator or the format!
macro.
Code example:
let mut s = String::from("Hello");
s.push_str(", world!");
println!("{}", s);
Output
Hello, world!
Explanation of code parts:
let mut s = String::from("Hello");
- This line creates a mutableString
variables
and assigns it the valueHello
.s.push_str(", world!");
- This line appends the string", world!"
to the existing strings
.println!("{}", s);
- This line prints the value ofs
to the console.
Helpful links:
More of Rust
- How to replace a capture group using Rust regex?
- How to use regex with bytes in Rust?
- How to get an entry from a HashSet in Rust?
- How to replace strings using Rust regex?
- Regex example to match multiline string in Rust?
- How to use regex to match a double quote in Rust?
- How to match the end of a line in a Rust regex?
- How to perform matrix operations in Rust?
- How to parse JSON string in Rust?
- How to use regex to match a group in Rust?
See more codes...