FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour String to array using 2 different delimiters
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
String to array using 2 different delimiters
Posted: Fri Aug 09, 2019 12:59 PM
Hello,

what is the best solution to build a structured array from a textline with 2 delimiters ?

maybe a char replace of < - > with blancs
next splitting the line for < ; >
and splitting blancs :-)

Delimiter Fields < ; >
Delimiter Fieldinfos < - >

Code (fw): Select all Collapse
FIRST-C-20-0;LAST-C-20-0;STREET-C-30-0;CITY-C-30-0;HIREDATE-D-8-0

the wanted result
DBF-structure

FIRST       C   20  0
LAST        C   20  0
STREET      C   30  0
HIREDATE    D    8  0


regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: String to array using 2 different delimiters
Posted: Fri Aug 09, 2019 01:31 PM
Code (fw): Select all Collapse
   cText    := "FIRST-C-20-0;LAST-C-20-0;STREET-C-30-0;CITY-C-30-0;HIREDATE-D-8-0"
   aData    := HB_ATokens( cText, ";" )
   AEval( aData, { |c,i| aData[ i ] := HB_ATokens( c, "-" ) } )


This is optional. Converts character values to numbers, dates, etc., as may be appropriate. This may or may not give the expected results in all cases.

Code (fw): Select all Collapse
   for each aRow in aData
      AEval( aRow, { |c,i| aRow[ i ] := uCharToVal( c ) } )
   next
Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: String to array using 2 different delimiters
Posted: Fri Aug 09, 2019 01:49 PM
Mr. Rao,

thank You very much for Your help

this solution is needed for the second new part of the CSV-tool
to convert CSV to DBF
using CSV headlines optional with or without fieldsize / type - infos.



after building the CSV-headline from inside the first toolpart
I added a xBrowse-stop for the test
works perfect :-)



best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: String to array using 2 different delimiters
Posted: Fri Aug 09, 2019 05:31 PM

FIRST-C-20-0;LAST-C-20-0;STREET-C-30-0;CITY-C-30-0;HIREDATE-D-8-0


Now this extra data for the headers is put inside the csv file with a editor ?
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: String to array using 2 different delimiters
Posted: Fri Aug 09, 2019 06:07 PM

Marc,

these extra data ( fieldtype and size ) are included
creating a CSV from any DBF with section 1( DBF to CSV )
Reading this created CSV a DBF can be created with section 2 without any extra work.

In section 2 ( CSV to DBF ) it will be possible to add missing types and sizes
of the CSV created with other programs like Excel.
After that the DBF can be created.
I can add a test to check for missing values.

I will try to make it easy to manage.

regards
Uwe :D

Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.

Continue the discussion