Tab delimited text to binary

<< Click to Display Table of Contents >>

Navigation:  Examples >

Tab delimited text to binary

Goal: parse tab delimited file containing encoding map and write result to binary file containing array of two integers.

File has header line. First column is integer number, other are hex numbers. Columns may have optional value after comma separator and  may contain asterisk.

 

CID        GB        GB-EUC        GBpc-EUC        GBT        GBT-EUC        GBTpc-EUC        GBK-EUC        GBKp-EUC        

0        *        *        *        *        *        *        *        *        *        *        *        *        *

1        *        *        20        *        *        20        *        20        20        0020        c2a0,20        00a0,0020        

2        *        *        21        *        *        21        *        21        21        0021        21        0021        00000021

571        2657        a6d7        a6d7        2657        a6d7        a6d7        a6d7        a6d7        a6d7        03c8        cf88        03c8        000003c8

572        2658        a6d8        a6d8        2658        a6d8        a6d8        a6d8        a6d8        a6d8        03c9        cf89        03c9        000003c9

573        2659,232cv        a6d9,a3acv        a6d9,a3acv        2659,232cv        a6d9,a3acv        a6d9,a3acv        a6d9,a3acv        

 

We are using String_Split to extract first value and HextoDec to convert hex string to integer.

 

THtSQL.FromFolder(SelectedFolder, 'select cast(a as int),  cast(hextodec(string_split(k, '','')) as int) 
 ' from cid where k != ''*'' and _row > 0)', []).ToBinaryFile('gbk.dat')