Hi,
What would be the equivalent in AMS5 of the String.CountDelimitedStrings in AMS4?
thanks
Professional Software Development Tools
Hi,
What would be the equivalent in AMS5 of the String.CountDelimitedStrings in AMS4?
thanks
There isn't one per se. You can use the function that were included with AMS5 to do change a delimited string to a table and then use Table.Count
or you could make your own function that would count the number of delimited sections in a string.Code:--[[ 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 Dislog.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, 1, false); 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 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); ]]-- function TableToDelimitedString(Table, Delimiter) strReturn = ""; for i, item in Table do strReturn = strReturn..item..Delimiter; end strReturn = String.TrimRight(strReturn,Delimiter); return strReturn; end
or something along those lines anyway. I have not tested the above code but give it a shot and see if it works for you.Code:function String.CountDelimitedStrings(sDelimitedString, sDelimiter) local nReturn = 0 local nPos = nil local nDelimiterLength = String.Length(Delimiter); if sDelimitedString == "" then return 0; end if sDelimiter == "" then return 0; end nPos = String.Find(sDelimitedString, sDelimiter, 1, false); while (nPos ~= -1) do nReturn = nReturn +1; nPos = String.Find(sDelimitedString, sDelimiter, nPos + nDelimiterLength, false); end return nReturn end
Tigg
TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
THANKS!
wow it look easy now![]()