Versqual

Untitled

Jun 27th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. function FindAny(str, what, which)
  2. local where = 0
  3. local a, b = nil, nil
  4. for i=1,#str do
  5. if str:sub(i,i + #what - 1) == what then
  6. where = where + 1
  7. if where == which then
  8. a, b = i, i+ #what-1
  9. break
  10. end
  11. end
  12. end
  13. return a, b
  14. end
  15.  
  16.  
  17. str = "Gold:90#Lvl:10#"
  18. str2 = "Lvl: lv, Gold: gold"
  19.  
  20. a, b = FindAny(str, "Gold:", 1)
  21. c, d = FindAny(str, "#", 1)
  22.  
  23. str2 = str2:gsub("gold", str:sub(b+1, d-1))
  24.  
  25. a, b = FindAny(str, "Lvl:", 1)
  26. c, d = FindAny(str, "#", 2)
  27.  
  28. str2 = str2:gsub("lv", str:sub(b+1, d-1))
  29.  
  30. print(str2)
Add Comment
Please, Sign In to add comment