-1

I would like to print out the grapheme clusters of which the code point from U+0021 to U+0100 in the Unicode table

for i in 21...100 {
    print("\u{i} ", terminator: "")
}

The compiler presented me the following error

enter image description here

Question: I guess I can't use the index from the for loop array as the Unicode Scalar indicator in the string interpretation. If so, what steps should I change to use the loop correctly

Many thanks

SLN
  • 4,304
  • 1
  • 29
  • 59

1 Answers1

1

The \u{n} special character works only with a literal hexadecimal number n. But you can create a unicode scalar from its numerical value:

for i in 0x21...0x100 {
    print(UnicodeScalar(i), terminator: "")
}
Martin R
  • 510,973
  • 84
  • 1,183
  • 1,314