1 Ekim 2012 Pazartesi

NSString length for 4-byte characters

If you worked with 4 bytes characters -such as emoji- on ios, you should have noticed that NSString handles those 4-byte characters a little different than expected. Well, I might be missing something but it counts a 4-byte emoji as 2 characters.

Hence, If you need to process a string which contains a 4-byte character, you might need some new methods to calculate the length or offset in that string. I wrote two category methods for this purpose. One finds the length of the string and the other converts an offset calculated by NSString methods to the correct value. Feel free to use them if you need:


Note: NSString counts a 3-byte character as 1 character as expected.

Hiç yorum yok:

Yorum Gönder