Doom30

Casino Core

Jan 22nd, 2022 (edited)
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. --------------------------------------------
  2. -- * Core functions for Casino Programs * --
  3. --------------------------------------------
  4.  
  5. -- Split String function
  6. ------------------------------------
  7. -- Used largely for communications
  8. -- Separates strings into a table
  9. --   of substrings using delimiters
  10. ------------------------------------
  11. -- str  : The string to split
  12. -- delim: The delimiter to use (:)
  13.  
  14. function SplitString( str, delim )
  15.     if not str then return {} end
  16.     if not delim then delim = ":" end
  17.    
  18.     local tbl = {}                -- Initial Table
  19.     local ptn = "[^"..delim.."]*" -- Pattern
  20.     local fin = {}                -- Final Table
  21.    
  22.     str:gsub( ptn, function(x) tbl[#tbl+1] = x end )
  23.    
  24.     for i=1, #tbl do
  25.         if not (tbl[i] == "") then
  26.             fin[#fin+1] = ((tbl[i] == " ") and "" or tbl[i])
  27.         end
  28.     end
  29.    
  30.     return fin
  31. end
  32.  
  33. -- Merge String function
  34. ------------------------------------
  35. -- Used largely for communications
  36. -- Merges a table of strings into a
  37. --   single string to communicate
  38. ------------------------------------
  39. -- tbl  : The table to merge
  40. -- delim: The delimiter to use (:)
  41.  
  42. function MergeString( tbl, delim )
  43.     if not tbl then return "" end
  44.     if not delim then delim = ":" end
  45.    
  46.     local str = ((tbl[1] == "") and " " or tbl[1])
  47.    
  48.     for i=2, #tbl do
  49.         str = str..delim..((tbl[i] == "") and " " or tbl[i])
  50.     end
  51.    
  52.     return str
  53. end
Add Comment
Please, Sign In to add comment