this post was submitted on 15 Mar 2026
75 points (97.5% liked)
Rust
7864 readers
11 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You have a few options here, but the easiest is to collect into a
Vec<char>, replace the character there, then do aString::from_iter(chars)to get it back as a string.You can also manipulate the original chars iterator directly through takes, skips, and so on and
collectit into a string, but that's more complicated.Also, "character" is such a complicated concept because unicode is not simple. If you can work directly with bytes though, you can convert the string to a
Vec<u8>(which is the underlying type forString), manipulate that directly, then doString::from_utf8(or the same method forstr) to convert it back to a string.