Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: UDF CSV Item Extracting
#DefineFunction FindCSVDelim(line,num) ;DebugTrace(@ON,"xxxdebug.txt") dcount=0 inq=0 lastwasq=0 len=strlen(line) for xx=1 to len char=strsub(line,xx,1) if char=='"' then inq = (inq==0) if char=="," && inq==0 dcount=dcount+1 if dcount==num then return(xx) endif next return (len) #EndFunction #DefineFunction CSVCount(line) ;DebugTrace(@ON,"xxxdebug.txt") dcount=1 inq=0 lastwasq=0 len=strlen(line) for xx=1 to len char=strsub(line,xx,1) if char=='"' then inq = (inq==0) if char=="," && inq==0 dcount=dcount+1 endif next return (dcount) #EndFunction #DefineFunction CSVItemExtract(line,num) ;DebugTrace(@ON,"xxxdebug.txt") indexB=FindCSVDelim(strcat(line,","),num) anum=num-1 if anum==0 indexA=1 else indexA=FindCSVDelim(line,anum)+1 endif line=strsub(line,indexA,indexB-indexA) if strsub(line,1,1)=='"' && strsub(line,strlen(line),1)=='"' line=strsub(line,2,strlen(line)-2) endif return (line) #EndFunction testline=`"3170135","REYES,REINA","5","1073","LAKESHORE","RD","E","MISSISSAUGA","ON","L5E1E8",""` x=CSVCount(testline) Message("Number of items on line",x) y=CSVItemExtract(testline,2) Message("Second Item",y)
Article ID: W15725
File Created: 2003:05:13:11:29:52
Last Updated: 2003:05:13:11:29:52