MudkipTheEpic

Find And Replace API [WIP]

Feb 6th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.55 KB | None | 0 0
  1. function findAndReplace(string,data,replacedata)
  2. if not type(string) == "string" and type(data) == "string" and type(replacedata) == "string" then error("All 3 vars must be strings") end
  3. while true do
  4. pos = string.find(string,data)
  5. if pos==nil then break end
  6. j=j or true
  7. string=string..""
  8. local offset=string.len(string)+string.len(replacedata)
  9. offset=offset-string.len(data)
  10. local lastpos=pos + string.len(replacedata)
  11. string = string.sub(string, 1, pos-1)..replacedata..string.sub(string, lastpos,string.len(string)+offset)
  12. end
  13. return j and string
  14. end
Advertisement
Add Comment
Please, Sign In to add comment