Advertisement
NanoBob

string split

Dec 24th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.42 KB | None | 0 0
  1. fullString="1,5,10"
  2.  
  3. function splitString(sourceString,splittingChar,index)
  4.     for i=1,index do
  5.         start,stop=string.find(sourceString,splittingChar)
  6.         if start==nil then
  7.             start=string.len(sourceString)+1
  8.             stop=start
  9.         end
  10.         splittedString=string.sub(sourceString,0,start-1)
  11.         sourceString=string.sub(sourceString,stop+1,string.len(sourceString))
  12.     end
  13.     return splittedString
  14. end
  15.  
  16. print(splitString(fullString,",",3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement