[rust-dev] Using String and StrSlice

Christophe Pedretti christophe.pedretti at gmail.com
Sun Jun 1 11:20:49 PDT 2014


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 =
buf.as_slice().slice_to(i).to_string().append("a").append(buf.as_slice().slice_from(i+1))

if c is any UTF8 character, i can use
buf =
buf.as_slice().slice_to(i).to_string().append("a").append(buf.as_slice().slice_from(i+c.len_utf8_bytes()))

It's quite complex, no better way to do ?

Any future additional methods for String are planned ?

Thanks

-- 
Christophe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140601/11452ef4/attachment.html>


More information about the Rust-dev mailing list