String to array using 2 different delimiters

String to array using 2 different delimiters

Postby ukoenig » 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: Select all  Expand view  RUN

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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: String to array using 2 different delimiters

Postby nageswaragunupudi » Fri Aug 09, 2019 1:31 pm

Code: Select all  Expand view  RUN
  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: Select all  Expand view  RUN
  for each aRow in aData
      AEval( aRow, { |c,i| aRow[ i ] := uCharToVal( c ) } )
   next
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10654
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: String to array using 2 different delimiters

Postby ukoenig » Fri Aug 09, 2019 1: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.

Image

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

Image

best regards
Uwe :D
Last edited by ukoenig on Sat Aug 10, 2019 8:00 am, edited 1 time in total.
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: String to array using 2 different delimiters

Postby Marc Venken » Fri Aug 09, 2019 5: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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1446
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: String to array using 2 different delimiters

Postby ukoenig » Fri Aug 09, 2019 6: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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 43 guests