'How can I change the string received by readLine() method from NFD to NFC in Swift?
I need to input Hangul(Korean) with readline(). However, when input is received with readline(), consonants and vowels are separated. This is example:
let input = readLine()! // input: 한글
print(input) // ㅎㅏㄴㄱㅡㄹ
Looking at the documentation, readline() used UTF-8 method. I know that it can represent Hangul without any problem.
So, I think the reason is because Apple uses NFD method. So I used precomposedStringWithCanonicalMapping and precomposedStringWithCompatibilityMapping from NFD or NFKD way to NFC or NFKC way. But the result was the same...
let input = readLine()!
print(input.precomposeStringWithCanonicalMapping) // prints ㅎㅏㄴㄱㅡㄹ
print(input.precomposeStringWithCompatibilityMapping) // prints 하ㄴ그ㄹ
I'm not sure if my hypothesis is wrong or if the transformation method is wrong. I hope you can give me a clue to solve the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
