March 05, 2021, 07:54:54 AM

Author Topic: [bb] Split CSV parameters out of a string by AngelEyes [ 1+ years ago ]  (Read 613 times)

Offline BlitzBot

Title : Split CSV parameters out of a string
Author : AngelEyes
Posted : 1+ years ago

Description : 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

Code :
Code: BlitzBasic
  1. Dim split_params$(500)
  2.  
  3. Function SplitCSVLine%(l$,delim$)
  4.         param = 0
  5.         split_params$(param) = ""
  6.         quote = False
  7.         For loopy = 1 To Len(l$)
  8.                 bit$ = Mid$(l$,loopy,1)
  9.                 If bit$=Chr$(34) Then
  10.                         If quote = False Then
  11.                                 quote = True
  12.                         Else
  13.                                 quote = False
  14.                         End If
  15.                 ElseIf bit$=delim$ And quote = False Then
  16.                                 ; end of param
  17.                                 param = param + 1
  18.                                 split_params$(param) = ""
  19.                 Else
  20.                                 split_params$(param)=split_params$(param)+bit$
  21.                 End If
  22.         Next
  23.         Return param
  24. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal