rustrust string append
Rust strings are immutable, meaning that once created, they cannot be changed. However, it is possible to append a string to an existing string using the push_str() method.
Example code
let mut s = String::from("Hello");
s.push_str(", world!");
Output example
Hello, world!
The code above creates a String object called s and assigns it the value Hello. The push_str() method is then used to append the string , world! to the existing string. The result is a new string with the value Hello, world!.
The push_str() method takes a &str as an argument, so it is possible to append a string literal or a string slice to an existing string.
Helpful links
More of Rust
- Regex example to match multiline string in Rust?
- How to replace a capture group using Rust regex?
- How to use regex captures in Rust?
- How to replace strings using Rust regex?
- How to use non-capturing groups in Rust regex?
- How to use regex lookbehind in Rust?
- How to match the end of a line in a Rust regex?
- How to perform matrix operations in Rust?
- How to split a string with Rust regex?
- How to use regex lookahead in Rust?
See more codes...