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

Jussi Lahtinen jussi.lahtinen at gmail.com
Wed Sep 1 00:00:07 CEST 2021


Private Function ParseData(sData As String) As String[][]

  Dim sTemp As String[] = Split(Replace(sData[2, Len(sData) - 5], "}},",
""), "{")
  Dim sParsed As New String[][sTemp.Count]

  For ii As Integer = 0 To sTemp.Max
    sParsed[ii] = Split(sTemp[ii], ",")
  Next

  Return sParsed

End



Jussi

On Tue, Aug 31, 2021 at 2:54 PM Roberto Premoli <roberto.premoli at tiscali.it>
wrote:

> 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/20210901/242950f8/attachment.htm>


More information about the User mailing list