-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,772
  • 2
  • 38
  • 79

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
  • 529,903
  • 94
  • 1,240
  • 1,382