string - Converting Character and CodePoint in Swift -
can convert directly between swift character , unicode numeric value? is:
var i:int = ... // plain integer index. var mycodeunit:uint16 = mystring.utf16[i] // mychar = mycodeunit character, or equivalent.
or...
var j:string.index = ... // not integer! var mychar:character = mystring[j] // mycodeunit = mychar uint16
i can say:
mycodeunit = string(mychar).utf16[0]
but means creating new string each character. , doing thousands of times (parsing text) lot of new strings being discarded.
the type character
represents "unicode grapheme cluster", can multiple unicode codepoints. if want 1 unicode codepoint, should use type unicodescalar
instead.
Comments
Post a Comment