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
- Regex example to match multiline string in Rust?
- How to use regex captures in Rust?
- How to use binary regex in Rust?
- How to print a Rust HashMap?
- How to use regex to match a double quote 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 match a URL with a regex in Rust?
- How to use regex with bytes in Rust?
- How to make regex case insensitive in Rust?
See more codes...