--[[
Function: DelimitedStringToTable
Purpose: Breaks up a string given a delimiter into a table
Arguments:	DelimitedString - The string to parse
			Delimiter - The delimiter
Returns: A numerically indexed table with the string elements
Example:

string = "Brett,Mark,Darryl,Lorne,Adam";
tbResults = DelimitedStringToTable(string,",");
for i, name in tbResults do
	Dialog.Message("Name",name);
end

]]--
function DelimitedStringToTable(DelimitedString, Delimiter)
	tbReturn = {};
	local strWorking;
	local nPos = nil;
	local strData;
	local nTableIndex = 1;
	local nDelimiterLength = String.Length(Delimiter);
	
	if(nDelimiterLength < 1)then
		tbReturn[nTableIndex] = DelimitedString;
		return tbReturn;
	end
	
	strWorking = DelimitedString;
	nPos = String.Find(strWorking,Delimiter);
	while(nPos ~= -1)do
		strData = String.Left(strWorking,nPos-1);
		tbReturn[nTableIndex] = strData;
		nTableIndex = nTableIndex + 1;
		local nLength = String.Length(strWorking);
		strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
		nPos = String.Find(strWorking,Delimiter);
	end
	if(strWorking ~= "")then
		tbReturn[nTableIndex] = strWorking;
	end
	
	return tbReturn;
end
------------------------------------------------------
function TableToDelimitedString(Table, Delimiter)
	strReturn = "";
	for i, item in Table do
		strReturn = strReturn..item..Delimiter;
	end
	strReturn = String.TrimRight(strReturn,Delimiter);
	return strReturn;
end

--[[
Function: TableToDelimitedString
Purpose: Makes a table into a delimited string
Arguments:	Table - The table to make into a string
			Delimiter - The delimiter
Returns: A delimited string of the table elements
Example:

tbNames = {};
tbNames[1] = "Brett";
tbNames[2] = "Mark";
tbNames[3] = "Darryl";
tbNames[4] = "Lorne";
tbNames[5] = "Adam";

strOutput = TableToDelimitedString(tbNames,",");
Dialog.Message("Result",strOutput);

]]--