This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
split "%" from a string
Started by FuuuAInfiniteLoop(F.A.I.L), 28 February 2013 - 09:03 AMPosted 28 February 2013 - 10:03 AM
anyonw knows how to split the % character from a string?
Posted 28 February 2013 - 10:17 AM
I believe the code is like
tbl = {}
for word in string.gmatch(str, "%%a%") do print(word) end
Edit dont works :(/>
tbl = {}
for word in string.gmatch(str, "%%a%") do print(word) end
Edit dont works :(/>
Posted 28 February 2013 - 10:26 AM
Do you mean if you had string, say "Test 123%456" you could remove it, therefore making it "Test 123456"?
If so, do this:
If so, do this:
aString = "Test 123%456"
aString = string.gsub("%%", "")
-- aString is now Test123456
Posted 28 February 2013 - 10:35 AM
Do you mean split a string apart based on the placement of "%"s?
http://codepad.org/wlMBsKIy
http://codepad.org/Q4QnRUyG
http://codepad.org/wlMBsKIy
str = "Hello%world%foo%bar"
tbl = {}
str:gsub("[^%%]+", (function(word) table.insert(tbl, word) end))
or (in the form of a function)http://codepad.org/Q4QnRUyG
split_function = function(str)
local tbl = {}
str:gsub("[^%%]+", (function(word) table.insert(tbl, word) end))
return tbl
end
Posted 28 February 2013 - 10:51 AM
I mean this
str = lol%lol%rsd%asd%fds
i want to get the parts in bold, the quantity and the order can change as well as the contents
lol, rsd and asd are keys in a table that will be replaced
i want to use that string or %f%fs%sjdfjs%%ff%f%s% always getting the text that are in %%
str = lol%lol%rsd%asd%fds
i want to get the parts in bold, the quantity and the order can change as well as the contents
lol, rsd and asd are keys in a table that will be replaced
i want to use that string or %f%fs%sjdfjs%%ff%f%s% always getting the text that are in %%
Posted 28 February 2013 - 11:21 AM
string.match(str, "%%([^%%]+)%%") may do what you want. You'd probably want to use a string.gmatch loop, though.
Posted 28 February 2013 - 01:16 PM
If none of the above work, take a look on Google or StackOverflow for 'split string lua'.
Posted 28 February 2013 - 02:25 PM
Does no one read the Lua Manual anymore? All these answers are in there under String Munipulation (Pretty self-explanatory)