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
- Generator example in Rust
- How to replace a capture group using Rust regex?
- How to match a URL with a regex in Rust?
- How to use binary regex in Rust?
- How to use regex lookahead in Rust?
- How to make regex case insensitive in Rust?
- Regex example to match multiline string in Rust?
- How to use regex to match a double quote in Rust?
- Yield example in Rust
- How to use a tuple as a key in a Rust HashMap?
See more codes...