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 mutableStringvariablesand 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 ofsto the console.
Helpful links:
More of Rust
- How to get a capture group using Rust regex?
- How to use regex to match a double quote in Rust?
- How to replace strings using Rust regex?
- How to use non-capturing groups in Rust regex?
- Word boundary example in regex in Rust
- How to use regex to match a group in Rust?
- Example of struct private field in Rust
- How to multiply matrices in Rust?
- How to parse JSON string in Rust?
- How to initialize a Rust HashMap?
See more codes...