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

This code has been declared by its author to be Public Domain code.

Download source code

Split CSV parameters out of a string by AngelEyes2002
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

Comments

None.

Code Archives Forum