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 match whitespace with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to split a string with Rust regex?
- How to iterate over a Rust slice with an index?
- How to use negation in Rust regex?
- How to use regex captures in Rust?
- Regex example to match multiline string in Rust?
- How to get a capture group using Rust regex?
- How to use modifiers in a Rust regex?
- How to create a HashMap of structs in Rust?
See more codes...