var str = "u5f7cu884cu3067"
- for key, value in pairs(str):
- echo runeAt(str, key)
which outputs:
彼
½ ¼ 行 ¡ で §
Despite your registration name your code looks very wrong for me. I strongly assume that pairs iterates over bytes, not over runes. Inspect the runes module and maybe try something like:
import unicode
var str = "\u5f7c\u884c\u3067"
#for key, value in pairs(str):
for r in runes(str):
#echo runeAt(str, key)
echo r
The question was more centered around what the procedure of runeAt is for, not as much looking for a way to do what I have the code for.
does runeAt have any practical use?
Oh and the name is a declaration of intent, not a statement of capability.
The question was more centered around what the procedure of runeAt is for
That is impossible to guess from the subject of your message and from its text.
I am not sure for what runeAt() is intended, but from its documentation
Returns the rune in s at byte index i
and the fact that runes in unicode strings may occupy more than one single byte it is clear that when used in a loop of byte indices it will give the same rune multiple times.
import unicode
var str = "\u5f7c\u884c\u3067"
for r in runes(str):
echo r
Have you considered looking in the Nim Api docs?
https://nim-lang.github.io/Nim/unicode.html#runeLenAt%2Cstring%2CNatural
I have to admit that I didn't understand runeAt() either. This explains it:
from unicode import `$`
var str = "A\u5f7c\u884c\u3067Z"
for r in unicode.runes(str):
echo r
echo "That is what we expect."
for i in 0 .. 4:
echo unicode.runeAt(str, i)
echo "That was wrong. This is right."
var j = 0
for i in 0 .. 4:
echo unicode.runeAt(str, j)
j += unicode.runeLenAt(str, j)
A
彼
行
で
Z
That is what we expect.
A
彼
½
¼
行
That was wrong. This is right.
A
彼
行
で
Z