Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Recreating a string with references from a string (as table)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
sir-gunny
Advanced Cheater
Reputation: 0

Joined: 15 Mar 2012
Posts: 81

PostPosted: Fri Mar 18, 2022 11:27 am    Post subject: Recreating a string with references from a string (as table) Reply with quote

Hello.

I would like to use the references from a string to create a new string from it. The references are in a table. The strings have sometimes several references and sometimes none at all. Sometimes there are references that are not in the table. I do not know what to do at the moment. I hope you can help me. Sorry for my english, I use deepl.

Example:
Code:
MyString = [[{1101,2344} - {1102,874} \({3501,78} a {457,57}{74,978}\)!]]

MyBigTable = { [49] = {
[1101] = {[2344] = [[Hello]]},
[457] = {[57] = nil}, -- {457,57} does not exist in the table
[1102] = {[874] = [[World]]},
[3501] = {[78] = [[{8745,589} {84,987}]]},
[8745] = {[589] = [[This]]},
[84] = {[987] = [[is]]},
[74] = {[978] = [[test!]]}
}}


Code:
Hello - World (This is a test!)!
Back to top
View user's profile Send private message
sir-gunny
Advanced Cheater
Reputation: 0

Joined: 15 Mar 2012
Posts: 81

PostPosted: Sat Mar 19, 2022 3:10 pm    Post subject: Reply with quote

Hi.

I have tested around a bit and found this solution for me. Probably not the nicest but OK for me. Embarassed

Code:
function stringReplaceFromTable(sString,tTable)
 local d1,d2 = sString:match("{(%d+),(%d+)}")
 local sTemp = sString:gsub("{%d+,%d+}",tTable[tonumber(d1)] and tTable[tonumber(d1)][tonumber(d2)] or "",1)
 if sTemp:match("{%d+,%d+}") then
    return stringReplaceFromTable(sTemp,tTable)
 else
    sTemp = sTemp:gsub("\\","")
    return sTemp
 end
end
print(stringReplaceFromTable(MyString,MyBigTable[49]))
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites