Convert string from Shift-JIS to UTF-8 in Roblox Luau

Is it possible to convert string encode? :pray:
It looks like this in Shift-JIS
image
In Roblox It will
image

You can manually map a Shift-JIS byte sequences … and read it back converting it yourself.

manual map
--how that really works.
local sjisToUtf8 = {
	[0x82A0]="あ",  [0x82A1]="い",  [0x82A2]="う"
}

local i, result, byte1
function shiftJISToUTF8(sjisBytes)
	result = {} i = 1 byte1 = ""
	while i <= #sjisBytes do
		byte1 = string.byte(sjisBytes, i)
		if byte1 >= 0x80 then
			local byte2 = string.byte(sjisBytes, i + 1) or 0
			local sjisCode = bit32.bor(bit32.lshift(byte1, 8), byte2)
			table.insert(result, sjisToUtf8[sjisCode] or "?")
			i = i + 2
		else table.insert(result, string.char(byte1))
			i = i + 1
		end
	end
	return table.concat(result)
end

local shiftJISString = "\130\160" --"あ"
print(shiftJISToUTF8(shiftJISString))

Or just print it as a string… print(“あ”)

The utf8 library may be able to help you out here but since shift-jis is a different encoding scheme altogether you may be out of luck here.

is there anything preventing you from converting it to utf-8 before sending it to roblox? unfortunately I do not believe roblox supports non-utf8 encoding methods so you would have to manually convert codepoints yourself… you might be able to find a lua library that can already do this though, I’d try looking around