Difference between revisions of "Lua:readString"

From Cheat Engine
Jump to navigation Jump to search
m
m (Syntax Highlighting.)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' readString(''Address'', ''MaxLength'', [''WideChar'']) ''':''' String
+
{{CodeBox|'''function''' readString(''Address'', ''MaxLength'', [''WideChar'']) ''':''' String}}
  
 
Reads a string from the specified address in the currently opened (target) process until a 0-terminator is encountered.   
 
Reads a string from the specified address in the currently opened (target) process until a 0-terminator is encountered.   
Line 29: Line 29:
  
 
===Examples===
 
===Examples===
<pre>
+
<syntaxhighlight lang="lua" line>
 
-- Read an ASCII string from address 0x123456, up to 100 characters
 
-- Read an ASCII string from address 0x123456, up to 100 characters
 
local str = readString(0x123456, 100)
 
local str = readString(0x123456, 100)
Line 37: Line 37:
 
local wstr = readString("game.exe+1234", 256, true)
 
local wstr = readString("game.exe+1234", 256, true)
 
print("Wide string:", wstr)
 
print("Wide string:", wstr)
</pre>
+
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
=== Related Functions ===
+
{{RelatedStrings}}
* [[ansiToUtf8]]
+
 
* [[utf8ToAnsi]]
 
* [[translate]]
 
 
{{ReadWriteMemory}}
 
{{ReadWriteMemory}}

Latest revision as of 15:36, 25 June 2026

<> Lua API Reference

function readString(Address, MaxLength, [WideChar]) : String

Reads a string from the specified address in the currently opened (target) process until a 0-terminator is encountered. The maximum number of characters to read is limited by MaxLength to prevent freezing. Set WideChar to true if the string is encoded using widechar (UTF-16/Unicode) formatting.

Function Parameters[edit]

Parameter Type Description
Address Integer or CEAddressString The address in the target process to read from.
MaxLength Integer The maximum number of characters to read (prevents infinite loops; use 6000 if you don't care).
WideChar Boolean (optional) Set to true to read as a widechar (UTF-16/Unicode) string. Default is false (ASCII/ANSI).

Returns[edit]

String — The string read from the specified address.

Examples[edit]

1 -- Read an ASCII string from address 0x123456, up to 100 characters
2 local str = readString(0x123456, 100)
3 print("String:", str)
4 
5 -- Read a widechar (Unicode) string from a CEAddressString
6 local wstr = readString("game.exe+1234", 256, true)
7 print("Wide string:", wstr)

Main Pages

Core Lua documentation entry points

Lua
Script Engine

String Related Lua Functions

Encoding conversion and localized text helpers