rustrust string append char
Rust strings are immutable, meaning that once created, they cannot be changed. However, it is possible to append a single character to a string using the push method.
Example code
let mut s = String::from("Hello");
s.push('!');
Output example
Hello!
The code above creates a mutable string s with the value Hello. The push method is then used to append the character ! to the end of the string. The result is the string Hello!.
Helpful links
More of Rust
- How to perform matrix operations in Rust?
- How to match whitespace with a regex in Rust?
- How to convert a u8 slice to a hex string in Rust?
- How to match a URL with a regex in Rust?
- How to iterate through hashmap keys in Rust
- How to use Unicode in a regex in Rust?
- Regex example to match multiline string in Rust?
- How to make regex case insensitive in Rust?
- How to ignore case in Rust regex?
- How to use regex to match a double quote in Rust?
See more codes...