Why are String offsets so complicated?

Nope. But I can see why you're confused about my position. I'm advocating against using the cumbersome syntax altogether. I'm suggesting you instead use the iterator, or functions such as prefix and family. I'm suggesting that if you're trying to access specific indices of the character sequence, you're probably doing something wrong, and your algorithm is probably ported from some pseudo code that assumes both trivial encoding and presentation.

If you for some niche reason really need random access to a collection of characters, you should first convert your string into such a view, like so: let characters = Array(string) and use that for random access lookup or mutation.

1 Like