 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Tue Nov 01, 2016 11:27 pm Post subject: String manipulation in CE.(solved) |
|
|
1. In C#, there is String.Split method to split string into lines of smaller strings based on a delimiter. Is there a similar method in CE or a work around?
2. In CE, are there functions similar to ReadLine() and WriteLine() in .NET?
PS: I have check main.lua, but did not find anything similar.
Thanks in advance for your time.
Update:
With regard to the length of a string, can I use the length operator "#" to get the length of a given string?
Update 2:
I have found a way (sort of) to split strings in Lua:
| Code: |
words = {}
s = "This is a string"
for w in string.gmatch(s, "%a+") do
words[#words+1] = w
end
print(words[1])
print(words[2])
print(words[3])
print(words[4])
out will be:
This
is
a
string
|
|
|
| Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Wed Nov 02, 2016 12:37 am Post subject: |
|
|
Look into lua string library
https://www.lua.org/manual/5.3/manual.html#6.4
And tutorial
http://lua-users.org/wiki/StringLibraryTutorial
And patterns tutorial
http://lua-users.org/wiki/PatternsTutorial
One method to split strings,
| Code: | str = "hello, there, dear user"
pat = ",?" -- delimeter is "," and the question mark (?) represents optinal, basically makes lua capture characters until it hits first delimeter or end of the string.
tResults = {str:match((str:gsub("[^"..pat.."]*"..pat, "([^"..pat.."]*)"..pat)))} -- too many patterns and it will fail, you could always do it in a function instead
print(#tResults,unpack(tResults))
|
you can get string length by either or
if you want to read/write files by lines then heres one method to read a file by lines
| Code: | f = io.open("C:\\filename.txt", "r") -- opens a file to read
if (f) then
local data = f:read("*all"); -- gets all file data
f:close(); -- closes the file
for line in data:gfind("[^\n]+") do
print(line)
end
end |
_________________
I'm rusty and getting older, help me re-learn lua.
Last edited by daspamer on Wed Nov 02, 2016 12:40 am; edited 1 time in total |
|
| Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Wed Nov 02, 2016 12:40 am Post subject: |
|
|
| DaSpamer wrote: | Look into lua string library
https://www.lua.org/manual/5.3/manual.html#6.4
One method to split strings,
| Code: | str = "hello, there, dear user"
pat = ",?"
tResults = {str:match((str:gsub("[^"..pat.."]*"..pat, "([^"..pat.."]*)"..pat)))} -- too many patterns and it will fail, you could always do it in a function instead
print(#tResults,unpack(tResults))
|
you can get string length by either or
if you want to read/write files by lines then heres one method to read a file by lines
| Code: | f = io.open("C:\\filename.txt", "r") -- opens a file to read
if (f) then
local data = f:read("*all"); -- gets all file data
f:close(); -- closes the file
for line in data:gfind("[^\n]+") do
print(line)
end
end |
|
Thank you so much. I wasn't sure at the beginning whether I could use all the Lua libraries in CE.
|
|
| 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
|
|