Jump to content




split "%" from a string


  • You cannot reply to this topic
7 replies to this topic

#1 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 28 February 2013 - 10:03 AM

anyonw knows how to split the % character from a string?

#2 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

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 :(

#3 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

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:

aString = "Test 123%456"
aString = string.gsub("%%", "")
-- aString is now Test123456


#4 Watcher7

  • Members
  • 25 posts
  • LocationEquestria, TX

Posted 28 February 2013 - 10:35 AM

Do you mean split a string apart based on the placement of "%"s?
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


#5 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

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 %%

#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#7 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 28 February 2013 - 01:16 PM

If none of the above work, take a look on Google or StackOverflow for 'split string lua'.

#8 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

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)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users