|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Lynxz Gaming Expert Cheater Reputation: 4
Joined: 01 Jul 2017 Posts: 208 Location: help
|
Posted: Sun Feb 04, 2018 2:25 am Post subject: if contains then replace [Help] |
|
|
how to make if contains "this" then replace "this" to "that"
how? |
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sun Feb 04, 2018 4:29 am Post subject: Re: if contains then replace [Help] |
|
|
Lynxz Gaming wrote: | how to make if contains "this" then replace "this" to "that"
how? |
Code: | local x = 'this'
local y = 'that'
local z = 1
if z == 1 then
y = 'that'
x = 'this'
print(x..' is not '..y..' , right, Lynxz?')
else
print('I said '..x..' is not '..y..'. Why you asking?')
end |
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Sun Feb 04, 2018 4:56 am Post subject: |
|
|
that depends on what "this" is.
if it's just a string then you can use lua's gsub (short for global substitute) function eg.
Code: | -- ex 1
print(string.gsub('this will be replaced', 'this', 'that'))
-- ex 2
local thestring = 'this will be replaced'
print(string.gsub(thestring, 'this', 'that'))
print(thestring:gsub('this', 'that'))
-- ex 3
print(('this this his tis this this that'):gsub('this', 'that'))
|
see http://lua-users.org/wiki/StringLibraryTutorial for more examples
note that the number that's printed is because gsub also tells you how many times it did the substitution, to avoid that you can assign it to a variable which will only store the first result (the changed string).
If it's a table then you have to loop through the table and change this to that eg.
Code: | inthis = {'a','this',32, 'this', 'this', 42, 'that', {}, 'this'}
for k,v in pairs(inthis) do
if v == 'this' then
inthis[k] = 'that'
end
end
-- print changed table
for k,v in pairs(inthis) do print(v) end |
though if you have setup the table so what you want to change is in the index then you can just use table[this] = that eg. Code: | inthis = {}
inthis.a = 42
inthis.c = 325
inthis.this = 'not that'
inthis.wahtever = {}
if inthis.this then inthis.this = 'that' end
-- print changed table
for k,v in pairs(inthis) do print(v) end |
if it's an object from CE (like a stringlist) then you'd have to loop through by the count eg. Code: | for i=0,thestringlist.Count-1 do
if thestringlist[i] == 'this' then thestringlist[i] = 'that' end
end |
|
|
Back to top |
|
|
Lynxz Gaming Expert Cheater Reputation: 4
Joined: 01 Jul 2017 Posts: 208 Location: help
|
Posted: Mon Feb 05, 2018 6:13 am Post subject: |
|
|
what if i want replace a label like
if form.label.contains("this") then
form.label.caption = form.label.replace("this","that")
end
EDIT : nvm i solved it thanks! |
|
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
|
|