Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

SplitCommaSeparatedValuesMBS(text as string, delimiter as string = ",", quote as string = """") as string()
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
global method String MBS Util Plugin 11.3 Yes Yes Yes Yes No
Function: Splits a string with CSV values.
// 1. read a CSV file:

dim file as FolderItem = SpecialFolder.Desktop.Child("test.csv")
dim t as TextInputStream = TextInputStream.open(file)

// use right encoding for your file!
t.Encoding = encodings.MacRoman

while not t.EOF
dim line as string = t.ReadLine
dim items() as string = SplitCommaSeparatedValuesMBS(line)

// process items array

// 2. compare with split:

dim test as string = "Hello,""World,test"",end"

dim a() as string = split(test, ",")
dim b() as string = SplitCommaSeparatedValuesMBS(test, ",")

MsgBox Join(a,EndOfLine)+EndOfLine+EndOfLine+Join(b,EndOfLine)
Notes: This function is better for CSV data than the Split function as it handles quoted text right.

Some examples using this method:

Some FAQ entries about this method:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Util Plugin.

MBS Xojo blog