Code archives/File Utilities/Split CSV parameters out of a string

This code has not been declared by its author to be Public Domain code, and therefore should not be assumed to be so.

Download source code

Split CSV parameters out of a string by AngelEyes
(Posted 25 years ago)
After calling with the line to be split (l$) and the delimiter to use ("," is recommended) this function will return the number of parameters split up (0-return value).....these parameters are stored in the split_params$ array
Dim split_params$(500)

Function SplitCSVLine%(l$,delim$)
	param = 0
	split_params$(param) = ""
	quote = False
	For loopy = 1 To Len(l$)
		bit$ = Mid$(l$,loopy,1)
		If bit$=Chr$(34) Then
			If quote = False Then
				quote = True 
			Else
				quote = False
			End If
		ElseIf bit$=delim$ And quote = False Then
				; end of param
				param = param + 1
				split_params$(param) = ""
		Else
				split_params$(param)=split_params$(param)+bit$
		End If
	Next
	Return param 
End Function