My Swift strings cheatsheet

The Swift strings support representing Unicode strings natively. As such it is no longer possible to have random access inside the string because some characters might be represented on more than one byte.

I always forget how to do basic things so I put together a cheatsheet that might be useful to others too.

Counting characters



Iterating through the string characters


Indexes inside the string


Is string contained in another string


Split a string by separator, iteratively



Split a string by separator, recursively


Leave a Reply

Your email address will not be published. Required fields are marked *