'---------------------------------------------
function fieldcount(string s, string d) as sys
'=============================================
sys a,b,c,le,i
'
'EXCLUDE EMPTY STRINGS
'
le=len s
if le=0 then return 0
if d="" then return 1
'
b=asc d 'delimiter ascii code
c=1 'at least 1 field
i=0 'char index
while i<le
i+=1
a=asc s,i
'
'SKIP QUOTED TEXT " ' `
'
if a=34 or a=39
while i<le
i+=1
if i>le then exit while
if asc(s,i)=a then exit while
wend
end if
if a=b then c+=1
wend
return c
end function
INT numArg 'number of Arguments
STRING src,d$
d$=","
src="arg1,arg2,arg3,arg4,'and with coma, quoted field',arg6"
'call function
numArg=FieldCount(src,d$)
Print Str(numArg)
'extract arguments ******************************************
INT EPos,SPos
STRING arg1,arg2
EPos=0
SPos=0
'==========================================================
'first argument
IF numArg>0
SPos=1
EPos = InStr(SPos,src, ",")-1
Print "EPos:"+str(EPos)
If EPos <= 0 Then EPos = Len(src)
arg1 = RTrim(LTrim(Mid(src, SPos, EPos - SPos + 1)))
END IF
Print "ARG:"+arg1
'=============================================================
'second argument
IF numArg>1
SPos = EPos+2
EPos = InStr(SPos,src, ",") - 1
Print "EPos:"+str(EPos)
If EPos <= 0 Then EPos = Len(src)
arg2 = RTrim(LTrim(Mid(src, SPos, EPos - SPos + 1)))
END IF
Print "ARG:"+arg2