|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
st_of_dec Newbie cheater Reputation: 0
Joined: 04 Jan 2018 Posts: 10 Location: AUS
|
Posted: Wed Mar 13, 2019 10:18 am Post subject: Question for Lua replacing one letter with specific location |
|
|
Hi guys,
This question is more like pure LUA question, rather than celua.
Btw, thank Darkbyte for solving my problem last time.
Here we go. I got a script with 100 thousands letters, and I want to change one letter in a specific location. I have already got the location by using string.find() function, then I have totally no idea how to deal with it.
For instance,
Code: |
local s = [[ayzihblol,{A,3,+,%-,qiwhoiqwjnkgoiuapuj,lol,oisouhnqlolqppoz,lol,hjfapsqhuoqwjs]]
s1 = string.find(s,"iuapuj,") -- here is how I got the location
-- my result would be "ayzihblol,{A,3,+,%-,qiwhoiqwjnkgoiuapuj,XXX,oisouhnqlolqppoz,lol,hjfapsqhuoqwjs"
-- which I replace the first separate lol into XXX
|
I guess in this case, string.gsub() is out of use, because it is not only for global replacing, but also the module string is too difficult.
Regards.
_________________
gta5 creator st_of_dec |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Wed Mar 13, 2019 11:03 am Post subject: |
|
|
perhaps
string.sub(s,1,s1-1)..newstuff..string.sub(s,s1+1)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Wed Mar 13, 2019 11:18 am Post subject: |
|
|
If it's still just the first one you need to replace "gsub" will work.
http://lua-users.org/wiki/StringLibraryTutorial
Code: | local s = "Hello World, Hello World."
local s2 = string.gsub(s, "Hello", "Goodbye", 1)
print(s2) |
Quote: |
Goodbye World, Hello World. |
If you prefer placeholders, this is what I use.
Code: |
function interp(s, tbl)
if s == nil then return end
return (s:gsub('($%b{})', function(w) return tbl[w:sub(3, -2)] or w end))
end
local s = "Hello World, ${Greeting} World."
local s2 = interp(s, { Greeting = "Goodbye" })
print(s2) |
Quote: |
Hello World, Goodbye World. |
_________________
|
|
Back to top |
|
|
st_of_dec Newbie cheater Reputation: 0
Joined: 04 Jan 2018 Posts: 10 Location: AUS
|
Posted: Thu Mar 14, 2019 4:49 am Post subject: |
|
|
Dark Byte wrote: | perhaps
string.sub(s,1,s1-1)..newstuff..string.sub(s,s1+1) |
Thanks for solving my question again.
Here is an example of my final code.
Code: |
local s = "aaa".."bbb".."ccc"
print(s)
local lol = string.find(s,"b",1)
s = string.sub(s,1,lol-1).."ddd"..string.sub(s,lol+3)
print(s)
|
_________________
gta5 creator st_of_dec |
|
Back to top |
|
|
|
|
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
|
|