#How to get character in a &str at byte offset?

8 messages · Page 1 of 1 (latest)

gusty agate
#

That's the best/only way I think

#

If you need this in more places, create a helper function

#

Also note the usual: Are you sure dealing with individual chars is what you want?

carmine urchin
#

Are you sure pos doesn't cut a char in half?

gusty agate
#

The indexing checks that

carmine urchin
gusty agate
#

So does the unwrap if pos points at the end of the string

carmine urchin
#

And you want to work with chars not graphemes?