Hello,
i need unicode codes of any char in a string, but i dont get it. Can someone give me some clarity about unicodes in nim?
This is what i tried to understand them:
import
strutils,
unicode
proc getUnicode(c: string) =
let runeLen = c.runeLenAt(0)
echo "Length of " & $c & " is: " & $runeLen
for i in 0..<runeLen:
echo c[i].uint.toHex()
getUnicode("a") # gives "61" which is right
getUnicode("°") # gives "C2" and "B0", but only "B0" is '°'.
getUnicode("€") # gives "E2", "82" and "AC", but the unicode of '€' is "20AC".
import std/[strutils, unicode]
proc getUnicode(c: string) =
let len = runeLen(c)
echo "Length of ", c, " is: ", len
for i in 0..<len:
echo runeAtPos(c, i).uint.toHex()
getUnicode("a")
getUnicode("°")
getUnicode("€")
Seems to report everything properly.Thank you very much! This works for me well:
let runes = "a°€".toRunes()
for r in runes:
echo r.int16.toHex()
It can be more short using runes
for r in "a°€".runes:
echo r.int16.toHex()