Microsoft Small Basic

Program Listing: ZRL529
list = "sausages, ham, bacon, bread , eggs, apples ,bananas "

TextWindow.WriteLine("Enter a commas seperated list or press enter to use the default list.")
TextWindow.Write("> ")
newlist = TextWindow.Read()
If (Text.GetLength(newlist) > 0) Then
list = newlist
EndIf

'find the positions of the commas
numberOfCommas = 1
commas[numberOfCommas] = 1
For i = 1 To Text.GetLength(list)
If(Text.GetSubText(list, i, 1) = ",") Then
numberOfCommas = numberOfCommas + 1
commas[numberOfCommas] = i
EndIf
EndFor
commas[numberOfCommas + 1] = Text.GetLength(list) + 1

'TextWindow.WriteLine(commas)

'create a list
j = 1
For i = 1 To Array.GetItemCount(commas) - 1
'save all the letters between the commas
seperatedList[j] = Text.GetSubText(list,commas[i],commas[i+1] - commas[i])
'remove any spaces and commas from the beginning
While (Text.StartsWith(seperatedList[j], ",") Or Text.StartsWith(seperatedList[j], " "))
seperatedList[j] = Text.GetSubTextToEnd(seperatedList[j], 2)
EndWhile
'remove any spaces and commas from the end
While (Text.EndsWith(seperatedList[j], ",") Or Text.EndsWith(seperatedList[j], " "))
seperatedList[j] = Text.GetSubText(seperatedList[j], 1, Text.GetLength(seperatedList[j]) - 1)
EndWhile
j = j + 1
EndFor
'TextWindow.WriteLine(seperatedList)

'print the list
For i = 1 To Array.GetItemCount(seperatedList)
TextWindow.WriteLine(seperatedList[i])
EndFor