Serialize string to list

From Director Online Wiki
Jump to: navigation, search

Here's the code to convert a string to a list using whatever string you want as the delimiter:

on serializeStringToList InputString, ItemDelim
  OrigDelim = the itemDelimiter
  the itemDelimiter = ItemDelim
  OutputList = []
  TotalItems = InputString.item.count
  repeat with ItemIndex = 1 to TotalItems
    ItemString = InputString.item[ItemIndex]
    OutputList.append(ItemString)
  end repeat
  the itemDelimiter = OrigDelim
  return OutputList
end

example:
put serializeStringToList("1,2,3,4,5,6", ",")
-- ["1", "2", "3", "4", "5", "6"]