MatheusGlad 424 Posted March 21, 2011 Report Share Posted March 21, 2011 (edited) Ela funciona como a funçao string.gsub so que nao funciona com patterns... function stringsub(s, str, repl, n) n = n ~= nil and n or "inf" lastpos = 1 for i = 1, #s do if s:sub(i, i+#str-1) == str then if n == "inf" then s = s:sub(lastpos, i-1) .. repl .. s:sub(i+#str) a = a ~= nil and a+1 or 1 else if a == nil or a < n then s = s:sub(lastpos, i-1) .. repl .. s:sub(i+#str) a = a ~= nil and a+1 or 1 else break end end end end return s , a end Eu sei que dava pra fazer usando string.find facilmente. Mas nao teria graça ne? xD Edited March 21, 2011 by MatheusMkalo Link to comment https://xtibia.com/forum/topic/153799-fun%C3%A7ao-stringgsubs-str-repl-n/ Share on other sites More sharing options...
satan666 12 Posted April 21, 2011 Report Share Posted April 21, 2011 funciona como uma função iteradora? Link to comment https://xtibia.com/forum/topic/153799-fun%C3%A7ao-stringgsubs-str-repl-n/#findComment-1026692 Share on other sites More sharing options...
Recommended Posts