[rust-dev] Using String and StrSlice
someone at mearie.org
Sun Jun 1 21:32:54 PDT 2014
If your string is an ASCII, you can convert between `String` and
`Vec<Ascii>` using `to_ascii()` and `as_str_ascii()` methods. You can
then update an individual character in the vector. See `std::ascii`
for related traits.
Codepoint-wise operation is prone to error and I don't think such
methods would be added in the future. In general, do not think
`String` as a sequence of bytes or codepoints (Unicode scalar values
to be exact) or characters. Think it as a black box containing some
human text. `chars()` (a misnomer!) and `as_bytes()` should be used to
extract a list of codepoints and UTF-8 bytes from the string.
Codepoint-wise operations can always be done with `Vec<char>`.
2014-06-02 3:20 GMT+09:00 Christophe Pedretti <christophe.pedretti at gmail.com>:
> Hi all,
> suppose i want to replace the i th character c (this character is ascii, so
> represented by exactly one byte) in a String named buf with character 'a'
> i can do this
> buf =
> if c is any UTF8 character, i can use
> buf =
> It's quite complex, no better way to do ?
> Any future additional methods for String are planned ?
> Rust-dev mailing list
> Rust-dev at mozilla.org
-- Kang Seonghoon | Software Engineer, iPlateia Inc. | http://mearie.org/
-- Opinions expressed in this email do not necessarily represent the
views of my employer.
More information about the Rust-dev