Advertisement
Bolodefchoco_LUAXML

[String] string.jump

Mar 28th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 28/03/2016
  3. --Last update: 26/05/2016
  4. --[[ Notes:
  5.     Does:
  6.         Retorna a cadeia de words palavras pulando as palavras de jump
  7.     Args:
  8.         str --> String
  9.         words --> Deve ser um número inteiro para a quantidade de palavras da string retornada
  10.         jump --> Deve ser uma tabela com todas as palavras de str para serem puladas
  11. ]]--
  12.  
  13. string.jump=function(str,words,jump)
  14.     str,words,jump = str or "",tonumber(words) or #str,(jump ~= nil and (type(jump) ~= "table" and {jump} or jump) or {" "})
  15.     local newString,jumped,rest = {},0,0
  16.     for value in str:gmatch("[^%s]+") do
  17.         local bool = true
  18.         for k,v in next,jump do if v == value then bool = false;jumped=jumped+1 end end
  19.         if bool then if #newString+1 <= words then table.insert(newString,value) else rest=rest+1 end end
  20.     end
  21.     return table.concat(newString," "),jumped,rest
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement