Ever have formatting issues trying manipulate csv data?

Started by RAK, March 11, 2014, 10:39:06 PM

Previous topic - Next topic

RAK

Some fields have quotes around data - some do not - some fields have delimiters in the data. I found this a common issue when data is exported from web sites. This routine will quickly replace only extra comma delimiters (,) found within field text into (.) periods - then you simply replace all quotes with null to create clean csv data for reading. First: load data into a buffer i.e. (upgbuf).

      structure=BinaryTagInit(upgbuf,'"','"')
      While 1
         structure=BinaryTagFind(structure)
         If structure=="" Then Break
         if strindex ( BinaryTagExtr(structure, 1), ',', 1, @Fwdscan)
            fieldVal = strreplace ( BinaryTagExtr(structure, 1),',','.') ; replaces commas in field data with periods
            ;fieldVal = strreplace ( BinaryTagExtr(structure, 1),',','') ; or use this to remove commas in field data
            structure = BinaryTagRepl( structure, fieldVal )
         endif
      EndWhile