Is it possible to read a file directly into an array?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Is it possible to read a file directly into an array?

Fernando Cabral
Is there a straightforward way to read a file directly into an array?
Say I have a file with several lines (lines ended with "\n").
I want to read each line and push its content as an item of an array.

Lets say the file contents are "a\nb\nc\n" and what I need is:

word[0] = "a"
word[1] = "b"
word[2] = "c"

Yes, I know I can LINE INPUT each line and copy it into the array.
But I have seen that Gambas has so many shortcuts that perhaps there is one
for this operation too.

Any hints?

Regards

- fernando


--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: [hidden email]
Facebook: [hidden email]
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is it possible to read a file directly into an array?

Fernando Cabral
Well, I found a very easy way to do it:


*Dim Wordlist as string []*

*Wordlist = Split(File.Load("strings.txt"), "\n")*
It seems it can't be easier, can it?




2017-07-04 12:06 GMT-03:00 Fernando Cabral <[hidden email]>:

> Is there a straightforward way to read a file directly into an array?
> Say I have a file with several lines (lines ended with "\n").
> I want to read each line and push its content as an item of an array.
>
> Lets say the file contents are "a\nb\nc\n" and what I need is:
>
> word[0] = "a"
> word[1] = "b"
> word[2] = "c"
>
> Yes, I know I can LINE INPUT each line and copy it into the array.
> But I have seen that Gambas has so many shortcuts that perhaps there is
> one for this operation too.
>
> Any hints?
>
> Regards
>
> - fernando
>
>
> --
> Fernando Cabral
> Blogue: http://fernandocabral.org
> Twitter: http://twitter.com/fjcabral
> e-mail: [hidden email]
> Facebook: [hidden email]
> Telegram: +55 (37) 99988-8868 <(37)%2099988-8868>
> Wickr ID: fernandocabral
> WhatsApp: +55 (37) 99988-8868 <(37)%2099988-8868>
> Skype:  fernandojosecabral
> Telefone fixo: +55 (37) 3521-2183 <(37)%203521-2183>
> Telefone celular: +55 (37) 99988-8868 <(37)%2099988-8868>
>
> Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
> nenhum político ou cientista poderá se gabar de nada.
>
>


--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: [hidden email]
Facebook: [hidden email]
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is it possible to read a file directly into an array?

PICCORO McKAY Lenz
2017-07-04 11:29 GMT-04:30 Fernando Cabral <[hidden email]>:

> Well, I found a very easy way to do it:
>
>
> *Dim Wordlist as string []*
>
> *Wordlist = Split(File.Load("strings.txt"), "\n")*
> It seems it can't be easier, can it?
>
wow, very easy.. good made it


>
>
>
>
> 2017-07-04 12:06 GMT-03:00 Fernando Cabral <[hidden email]>:
>
> > Is there a straightforward way to read a file directly into an array?
> > Say I have a file with several lines (lines ended with "\n").
> > I want to read each line and push its content as an item of an array.
> >
> > Lets say the file contents are "a\nb\nc\n" and what I need is:
> >
> > word[0] = "a"
> > word[1] = "b"
> > word[2] = "c"
> >
> > Yes, I know I can LINE INPUT each line and copy it into the array.
> > But I have seen that Gambas has so many shortcuts that perhaps there is
> > one for this operation too.
> >
> > Any hints?
> >
> > Regards
> >
> > - fernando
> >
> >
> > --
> > Fernando Cabral
> > Blogue: http://fernandocabral.org
> > Twitter: http://twitter.com/fjcabral
> > e-mail: [hidden email]
> > Facebook: [hidden email]
> > Telegram: +55 (37) 99988-8868 <(37)%2099988-8868>
> > Wickr ID: fernandocabral
> > WhatsApp: +55 (37) 99988-8868 <(37)%2099988-8868>
> > Skype:  fernandojosecabral
> > Telefone fixo: +55 (37) 3521-2183 <(37)%203521-2183>
> > Telefone celular: +55 (37) 99988-8868 <(37)%2099988-8868>
> >
> > Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
> > nenhum político ou cientista poderá se gabar de nada.
> >
> >
>
>
> --
> Fernando Cabral
> Blogue: http://fernandocabral.org
> Twitter: http://twitter.com/fjcabral
> e-mail: [hidden email]
> Facebook: [hidden email]
> Telegram: +55 (37) 99988-8868
> Wickr ID: fernandocabral
> WhatsApp: +55 (37) 99988-8868
> Skype:  fernandojosecabral
> Telefone fixo: +55 (37) 3521-2183
> Telefone celular: +55 (37) 99988-8868
>
> Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
> nenhum político ou cientista poderá se gabar de nada.
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Loading...