Forum

> > CS2D > Scripts > Convert utf8 encoding to string
Forums overviewCS2D overview Scripts overviewLog in to reply

English Convert utf8 encoding to string

No replies
To the start Previous 1 Next To the start

old Convert utf8 encoding to string

ATRI
User Off Offline

Quote
This function is for lua hook sayutf8:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
local function utf8_from(t)
	local bytearr = {}
	for _, v in ipairs(t) do
		local utf8byte = v < 0 and (0xff + v + 1) or v
		table.insert(bytearr, string.char(utf8byte))
	end
	return table.concat(bytearr)
end

local function utf8_expend(str) -- Put message
	local t = {}
	for num in str:gmatch('[^x]+') do
		table.insert(t, tonumber(num, 16))
	end
	return utf8_from(t)
end
For example:
1
2
3
print(utf8_expend('x61x7A')) --> 'az'
print(utf8_expend('xE4xBDxA0xE5xA5xBD')) --> '你好'
print(utf8_expend('xD0x9FxD1x80xD0xB8xD0xB2xD0xB5xD1x82')) --> 'Привет'
Sorry, my English is poor
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview