Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------
- -- * Core functions for Casino Programs * --
- --------------------------------------------
- -- Split String function
- ------------------------------------
- -- Used largely for communications
- -- Separates strings into a table
- -- of substrings using delimiters
- ------------------------------------
- -- str : The string to split
- -- delim: The delimiter to use (:)
- function SplitString( str, delim )
- if not str then return {} end
- if not delim then delim = ":" end
- local tbl = {} -- Initial Table
- local ptn = "[^"..delim.."]*" -- Pattern
- local fin = {} -- Final Table
- str:gsub( ptn, function(x) tbl[#tbl+1] = x end )
- for i=1, #tbl do
- if not (tbl[i] == "") then
- fin[#fin+1] = ((tbl[i] == " ") and "" or tbl[i])
- end
- end
- return fin
- end
- -- Merge String function
- ------------------------------------
- -- Used largely for communications
- -- Merges a table of strings into a
- -- single string to communicate
- ------------------------------------
- -- tbl : The table to merge
- -- delim: The delimiter to use (:)
- function MergeString( tbl, delim )
- if not tbl then return "" end
- if not delim then delim = ":" end
- local str = ((tbl[1] == "") and " " or tbl[1])
- for i=2, #tbl do
- str = str..delim..((tbl[i] == "") and " " or tbl[i])
- end
- return str
- end
Add Comment
Please, Sign In to add comment