FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour dealing with a CSV file
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM
dealing with a CSV file
Posted: Sat May 15, 2010 05:22 PM

I am importing a comma delimited file and I need to make certain the user has set up the file properly.
Is there a way to count the delimiters (commas) in the file and fix it if it has too may delimiters. All has to be at run time and behind the scenes.

Thank you

Harvey
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: dealing with a CSV file
Posted: Sat May 15, 2010 07:11 PM
Harvey,

You can use NumAt() to count the commas in each line:

NUMAT(<cStringToMatch>, <cString>, [<nIgnore>]) --> nCount

To extract each line, in a fast way, you can use this code:
Code (fw): Select all Collapse
       local cText := MemoRead( "text.csv" ), cLine
       local nLen := Len( cText )
       local nFrom := 1

       While nFrom <= nLen
          cLine  := ExtractLine( cText, @nFrom )
          if NumAt( ",", cLine ) != 5 // number of ","
             MsgAlert( "error in line " + Str( nFrom - 1 ) )
          endif
       end
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM
Re: dealing with a CSV file
Posted: Sat May 15, 2010 09:57 PM

Thanks Antoonio.

I'll give it a try tomorrow.

Thank you

Harvey
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM
Re: dealing with a CSV file
Posted: Sat May 15, 2010 10:47 PM

Antonio

Where is the function numat() located. Won't compile.

Thank you

Harvey
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: dealing with a CSV file
Posted: Sat May 15, 2010 11:02 PM

Harvey,

If you are using Harbour then you have to link hbct.lib, if you use xHarbour then link ct.lib

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion