Re: How to enumerate by code points in Swift beta4?
Re: How to enumerate by code points in Swift beta4?
- Subject: Re: How to enumerate by code points in Swift beta4?
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Wed, 23 Jul 2014 15:58:04 +0700
On 23 Jul 2014, at 13:26, Roland King <email@hidden> wrote:
>> How can I get the Unicode code points (NOT unsigned shorts in utf-16 representation) as UInts (or Ints) ?
>> like: 0xe17, 0xe35, 0xe48.
>>
>> Gerriet.
>>
>
> If I understand what you’re asking here, that’s in the Swift iBook.
>
> … enumerate(ss.utf16) …
let ss = "Hello \u{1F30D}" // this has 7 code points, the last one is 0x1f30d
println("string \"\(ss)\" in utf16:")
for (i,s) in enumerate(ss.utf16)
{
let outFormated = NSString(format: "utf16[%2lu] = %#6x", i, s )
println(outFormated)
}
This prints:
string "Hello 🌍" in utf16:
utf16[ 0] = 0x48
utf16[ 1] = 0x65
utf16[ 2] = 0x6c
utf16[ 3] = 0x6c
utf16[ 4] = 0x6f
utf16[ 5] = 0x20
utf16[ 6] = 0xd83c <-- NOT a code point, but first part of a surrogate pair for 0x1f30d
utf16[ 7] = 0xdf0d
What I want is:
for (i,s) in enumerate(ss.utf32)
but this seems not to exist.
NSString can do it via dataUsingEncoding: NSUTF32LittleEndianStringEncoding.
Kind regards,
Gerriet.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden