String.sub doesn't work on russian characters

  1. What do you want to achieve? I want string.sub to work

  2. What is the issue? string.sub doesn’t work with russian characters for some reason

  3. What solutions have you tried so far? I tried turning the russian characters in the string into their english counterpart on the keyboard but that didn’t work either. What I mean is that for example, an “Ы” would be a “Y”. So the word “пистолет” would be “gbcnjtk”.

изображение

local russ = "ГА"

print(string.sub(russ, 2,2))

This code always returns the question mark sign (it’s supposed to say “А”):

изображение

please help me

1 Like

It seems to be because characters such as Ы and Г are counted as 2 seperate characters, due to the way Unicode works. Accessing just one of the 2 characters in each returns the question mark.

As for solutions: I’m not entirely sure what the best way of going about it is.

aw man I wanted to make a letter spelling game for my lil bro

Don’t give up hope! There’s a unicode library available (utf8) which I’ll examine to see if I can get it to work how you want.

In the meantime, attempting to access said library uncovered a bug in Roblox Studio, so I’ll probably report it.

alright, thank you very much :slight_smile:

Good news! I found a way on how to get it working.

It relies on looping through the entire string, but based on your use case that should be fine.

local russ =  "ГА"

for first, last in utf8.graphemes(russ) do
	char = string.sub(russ, first, last)
    print(char)
end

The above code will output Г, then А


edit: Here’s the report I posted about the bug I mentioned earlier.

2 Likes

you’re a lifesaver, thank you from the bottom of my heart, honestly I never really understood the encoding stuff :sweat_smile:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.