:split() doesn't recognize foreign characters

Using string.split or :split() on strings with unique characters will error out any letters it does not recognize.

local myString = "Test_é❤️"
local splitString = myString:split("") -- or can also use string.split(myString, "")

print(splitString)

--[[
prints out:

 ▼  {
	    [1] = "T",
	    [2] = "e",
	    [3] = "s",
	    [4] = "t",
	    [5] = "_",
	    [6] = "�",
	    [7] = "�",
	    [8] = "�",
	    [9] = "�",
	    [10] = "�",
	    [11] = "�",
	    [12] = "�",
	    [13] = "�"
	 } 
]]

An example of usage:
SplitStringTest.rbxm (4.3 KB)

Expected behavior

I’m not sure if this was the intended behavior or not, but I was hoping it would recognize special letters and emojis. I believe there are work arounds, but nonetheless just wanted to report on this since it was causing me some issues.

If I’m correct then this is intended as it’s probably because the font you use doesn’t support such special characters.

1 Like

The base string library operations like sub/split/# etc do not understand unicode text. If you want unicode awareness you must use the utf8 library.

In this case the API you wanted was probably utf8.graphemes which will split the string into the visually distinct groupings (working with stuff like colored emoji).

2 Likes

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