Mason11987
Mason11987

Reputation: 330

Loop through all Unicode extended grapheme clusters

The question addresses my main goal, but even being able to loop through all unicode scalars might be worthwhile.

In effect I'd like to be able to do something like:

for i in 0x0000...0xFFFF
{
    println("\u{i}")
}

Obviously with a larger range. It doesn't seem like you can interpolate strings into the /u escape character so I'm at a lost on how to do it.

Upvotes: 2

Views: 623

Answers (1)

Mike S
Mike S

Reputation: 42325

You can create a UnicodeScaler from a UInt8, UInt16, or UInt32 and then print that:

for i in 0x1000...0x1009 {
    let c = UnicodeScalar(i)
    print(c)
}

Outputs:

က ခ ဂ ဃ င စ ဆ ဇ ဈ ဉ

Upvotes: 4

Related Questions