Difference between revisions of "Lua:wideStringToByteTable"

From Cheat Engine
Jump to navigation Jump to search
m
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' wideStringToByteTable(''String'') ''':''' table
+
'''function''' wideStringToByteTable(''String'') ''':''' Table
  
Converts a string is encoded using a widechar formatting to a byte table.
+
Converts a string to a wide string (UTF-16/Unicode) and then to a table of bytes.
  
 
+
===Function Parameters===
=== Function Parameters ===
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
 
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
Line 12: Line 11:
 
|-
 
|-
 
|String
 
|String
|string
+
|String
|The widechar formated string to convert to a byte table
+
|The string to convert to a wide string and then to a byte table.
 
|}
 
|}
  
 +
===Returns===
 +
Table — A table containing the bytes representing the wide string (UTF-16/Unicode).
  
== Examples ==
+
===Examples===
  local bt = wideStringToByteTable('player.weapons.rifle')
+
<pre>
  bt[#bt + 1] = 0
+
local bytes = wideStringToByteTable("ABC")
  bt[#bt + 1] = 0
+
for i, b in ipairs(bytes) do
  writeBytes('00123ABC', bt)
+
  print(string.format("Byte %d: %02X", i, b))
 
+
end
 
+
-- Output: 6 bytes representing "A", "B", "C" as UTF-16LE (e.g., 41 00 42 00 43 00)
Code:
+
</pre>
  local bt = wideStringToByteTable('test')
 
  for i, v in ipairs(bt) do
 
    print(i - 1, string.format('%02X', v))
 
  end
 
 
 
Output:
 
  0 74
 
  1 00
 
  2 65
 
  3 00  
 
  4 73
 
  5 00  
 
  6 74
 
  7 00  
 
 
 
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}

Revision as of 17:28, 11 July 2025

function wideStringToByteTable(String) : Table

Converts a string to a wide string (UTF-16/Unicode) and then to a table of bytes.

Function Parameters

Parameter Type Description
String String The string to convert to a wide string and then to a byte table.

Returns

Table — A table containing the bytes representing the wide string (UTF-16/Unicode).

Examples

local bytes = wideStringToByteTable("ABC")
for i, b in ipairs(bytes) do
  print(string.format("Byte %d: %02X", i, b))
end
-- Output: 6 bytes representing "A", "B", "C" as UTF-16LE (e.g., 41 00 42 00 43 00)

See also

Related Functions