rustHow do I append a string in Rust?
You can append a string in Rust using the push_str()
method. This method takes a string slice as an argument and appends it to the end of the string.
Example code
let mut s = String::from("Hello ");
s.push_str("World!");
Output example
Hello World!
Code explanation
let mut s = String::from("Hello ");
: This line creates a mutableString
variables
and assigns it the valueHello
.s.push_str("World!");
: This line calls thepush_str()
method on thes
variable, passing in the stringWorld!
as an argument. This appends the stringWorld!
to the end of thes
variable.
Helpful links
More of Rust
- How to replace a capture group using Rust regex?
- How to split a string with Rust regex?
- How to get all matches from a Rust regex?
- How to use backslash in regex in Rust?
- How to use regex with bytes in Rust?
- How to use regex lookahead in Rust?
- How to use regex to match a double quote in Rust?
- How to add matrices in Rust?
- How to use non-capturing groups in Rust regex?
- How to make regex case insensitive in Rust?
See more codes...