[Gambas-user] import data from text file and popolate a 2D array

Carlos Kabronsete carloskabronsete at gmail.com
Tue Aug 31 20:40:55 CEST 2021


Hi

See the example

Dim Data1 as string, data2 as new String[], Data3 as new String[], Counter
as integer

Data1="[{field1,field2,...fieldN}},{field1,field2,...fieldN}},...{field1,field2,...fieldN}}]"
Data1=Replace(Data1,"[","") 'remove garbage
Data1=Replace(Data1,"]","") 'remove garbage
Print Data1
{field1,field2,...fieldN}},{field1,field2,...fieldN}},...{field1,field2,...fieldN}}

Data2=split(Data1,"}")

Print Data2[0]
{field1,field2,...,fieldN
Print Data2[1]
,{field1,field2,...,fieldN

Now the same with those strings.
Data2[0]=Replace(Data2[1],"{","") 'remove garbage
Print Data2[0]
field1,field2,...,fieldN

The same with element Data2[1], It start with comma.
Data2[1]=Replace(Data2[1],",{","") 'remove garbage
Print Data2[1]
field1,field2,...,fieldN

Now you can separate on fields with comma delimiter.
Data3=split(Data2[1],",")
For counter=0 to Data3.max
   print Data3[Counter]
next
field1
field2
fiel ...
fieldN




El mar, 31 ago 2021 a las 13:54, Roberto Premoli (<
roberto.premoli at tiscali.it>) escribió:

> hello. i run gambas 3.12-2 (debian 10 stable)
>
> I have a list of raw data into a text file. It is a database as follow:
>
> [{field1,field2,...fieldN}},{field1,field2,...fieldN}},...{field1,field2,...fieldN}}]
>
> each line starts with "{", end with "}}" and inside each line, the
> fields are separated by ",".
>
> i wish to read the text file as input, get each "block" {...}}, and
> split it into fields to populate a database bidimentiona array (about
> 6000 linees and 20 fields in each line).
> I can elaborate all file database searching the "marker" ( the "{", the
> "," and the "}},") but I suppose it will be slow compared to a
> dedicated command (if it exist).
> I write here asking if there is some "magic trick" to elaborate strings
> that allow me to speed up all the process and avoid me to write
> a dedicated funcion.
>
> Thanks,
> Roberto
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210831/e9879911/attachment.htm>


More information about the User mailing list