List to Array
Moderator: Rathinagiri
-
- Posts: 119
- Joined: Wed Feb 18, 2009 2:14 pm
List to Array
Hello,
If I have a comma delimited list in a character variable (cMyList). How can I use it to initialize a one dimensional array (aMyArray)?
Example Var:
cMyList := "A,B,C,D,E"
Id like to use the array to loop through the values.
Example goal - simple loop through an array:
local nLenArray := len(aMyArray)
for i := 1 TO nLenArray
MsgInfo( aMyArray )
next
Thanks,
Michael
If I have a comma delimited list in a character variable (cMyList). How can I use it to initialize a one dimensional array (aMyArray)?
Example Var:
cMyList := "A,B,C,D,E"
Id like to use the array to loop through the values.
Example goal - simple loop through an array:
local nLenArray := len(aMyArray)
for i := 1 TO nLenArray
MsgInfo( aMyArray )
next
Thanks,
Michael
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: List to Array
Hello Michaelmelliott42 wrote:Hello,
If I have a comma delimited list in a character variable (cMyList). How can I use it to initialize a one dimensional array (aMyArray)?
Michael
Please take a look this sample:
Code: Select all
PROC Main()
LOCAL cMyList := "A,B,C,D,E"
LOCAL aMyArray := Strng2Arry( cMyList )
? cMyList
?
AEVAL( aMyArray, { | c1 | QOUT( c1 ) } )
WAIT
RETU // Main()
*.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
FUNC Strng2Arry( cString )
LOCA aRVal := {},;
c1Elem := ''
TOKENINIT( cString, ',', 1 )
WHILE !TOKENEND()
c1Elem := TOKENNEXT( cString )
AADD( aRVal, c1Elem )
ENDDO
TOKENEXIT()
RETU aRVal // Strng2Arry()
*.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
I hope that helps you.
Regards
--
esgici
Viva INTERNATIONAL HMG
- luisvasquezcl
- Posts: 1258
- Joined: Thu Jul 31, 2008 3:23 am
- Location: Chile
- Contact:
Re: List to Array
Hola esgici,
excelente ejemplo,
todos los dias se aprende algo nuevo .... y cada dia me sorprendo más.
No tenia idea que existian las funciones tokenend y tokennext ... son de harbour o hmg?
saludos cordiales,
Hello esgici,
excellent example
every day you learn something new .... I am amazed every day and more.
I had no idea that there tokenend and functions tokennext ... are harbor or HMG?
best regards,
Luis Vàsquez
excelente ejemplo,
todos los dias se aprende algo nuevo .... y cada dia me sorprendo más.
No tenia idea que existian las funciones tokenend y tokennext ... son de harbour o hmg?
saludos cordiales,
Hello esgici,
excellent example
every day you learn something new .... I am amazed every day and more.
I had no idea that there tokenend and functions tokennext ... are harbor or HMG?
best regards,
Luis Vàsquez
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: List to Array
Hi All
Luis, thanks your question. Answer is : all *token* functions are from Harbour.
List is :
TOKENINIT : Initializes a token environment
TOKEN : Tokens of a string
TOKENSEP : Retrieves the token separators of the last token() call
ATTOKEN : Position of a token in a string
TOKENAT : Get start and end positions of tokens in a token environment
TOKENUPPER : Change the first letter of tokens to upper case
TOKENLOWER : Change the first letter of tokens to lower case
TOKENNEXT : Successivly obtains tokens from a string
NUMTOKEN : Retrieves the number of tokens in a string
TOKENEND : Check whether additional tokens are available with TOKENNEXT()
TOKENEXIT : Release global token environment
SAVETOKEN : Save the global token environment
RESTTOKEN : Restore global token environment
HB_ATOKENS : Split up a string, based on a delimiter.
Your question remind me HB_ATOKENS().
And, I want to correct the above sample:
Please extract Strng2Arry() function completely and change its calling line like this :
LOCAL aMyArray := HB_ATOKENS( cMyList, ',' )
System functions are always better than UDF
Regards
--
esgici
Luis, thanks your question. Answer is : all *token* functions are from Harbour.
List is :
TOKENINIT : Initializes a token environment
TOKEN : Tokens of a string
TOKENSEP : Retrieves the token separators of the last token() call
ATTOKEN : Position of a token in a string
TOKENAT : Get start and end positions of tokens in a token environment
TOKENUPPER : Change the first letter of tokens to upper case
TOKENLOWER : Change the first letter of tokens to lower case
TOKENNEXT : Successivly obtains tokens from a string
NUMTOKEN : Retrieves the number of tokens in a string
TOKENEND : Check whether additional tokens are available with TOKENNEXT()
TOKENEXIT : Release global token environment
SAVETOKEN : Save the global token environment
RESTTOKEN : Restore global token environment
HB_ATOKENS : Split up a string, based on a delimiter.
Your question remind me HB_ATOKENS().
And, I want to correct the above sample:
Please extract Strng2Arry() function completely and change its calling line like this :
LOCAL aMyArray := HB_ATOKENS( cMyList, ',' )
System functions are always better than UDF
Regards
--
esgici
Viva INTERNATIONAL HMG
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: List to Array
It is just gr8. I didn't know about this either.
Still how many hidden treasures available?!
Still how many hidden treasures available?!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: List to Array
Hello Rathinagirirathinagiri wrote:It is just gr8. I didn't know about this either.
Still how many hidden treasures available?!
If you remember, I have said : this is a "Tantalos Torture". We have a real treasure and we can't know why we benefit from it, because of lack of documentation.
This isn't a exaggeration: Harbour became the biggest and most powerfull compiler of the world. Only deficiency is documentation.
Regards
--
esgici
Viva INTERNATIONAL HMG
-
- Posts: 119
- Joined: Wed Feb 18, 2009 2:14 pm
Re: List to Array
esgici,
>> LOCAL aMyArray := HB_ATOKENS( cMyList, ',' )
That worked great! Thanks.
>> Only deficiency is documentation.
Does HMG have a Wiki? If not maybe we can create one so as the load to create and update the docs is done by the HMG user coummunity.
If this is something you are interested in I'd be glad to set one up for us. I recommend MediaWiki. That is what Wikipedia uses. It is easy to setup and easy to make changes to.
Michael
>> LOCAL aMyArray := HB_ATOKENS( cMyList, ',' )
That worked great! Thanks.
>> Only deficiency is documentation.
Does HMG have a Wiki? If not maybe we can create one so as the load to create and update the docs is done by the HMG user coummunity.
If this is something you are interested in I'd be glad to set one up for us. I recommend MediaWiki. That is what Wikipedia uses. It is easy to setup and easy to make changes to.
Michael
- luisvasquezcl
- Posts: 1258
- Joined: Thu Jul 31, 2008 3:23 am
- Location: Chile
- Contact:
Re: List to Array
Hi,
It is true what they said esgici, documentation is an
the problems of harbor, that does not allow for andalusia
possible tool, which is very powerful. Moreover,
many other developers could see that it is not only a
clone clipper as presented but more than that.
Regards,
Luis VAsquez
Es cierto lo que comenta esgici, la documentación es uno
de los problemas de harbour, eso no permite aprovechar al
máximo la herramienta, la cual es muy poderosa. Además,
muchos otros programadores podrían ver que no es sólo un
clon de clipper como se presenta sino mucho más que eso.
Saludos
Luis VAsquez
It is true what they said esgici, documentation is an
the problems of harbor, that does not allow for andalusia
possible tool, which is very powerful. Moreover,
many other developers could see that it is not only a
clone clipper as presented but more than that.
Regards,
Luis VAsquez
Es cierto lo que comenta esgici, la documentación es uno
de los problemas de harbour, eso no permite aprovechar al
máximo la herramienta, la cual es muy poderosa. Además,
muchos otros programadores podrían ver que no es sólo un
clon de clipper como se presenta sino mucho más que eso.
Saludos
Luis VAsquez
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: List to Array
Hello Michaelmelliott42 wrote:
Does HMG have a Wiki? If not maybe we can create one so as the load to create and update the docs is done by the HMG user coummunity.
If this is something you are interested in I'd be glad to set one up for us. I recommend MediaWiki. That is what Wikipedia uses. It is easy to setup and easy to make changes to.
Documentation deficiency is for Harbour, no HMG.
Harbour team works very hardly and don't have extra time for documentation. Anyway, good programmer are bad
documentors Still Roberto Lopez is an exception. HMG docs are perfect, samples also. Complete, short, concentrated, easy to understand and effective.
The "wiki" subject was discussed in Harbour Developpers Mail List. As far as I know, yet there isn't any neat result.
Thanks for your nice proposal. But I can't decide anything like this. Anyway, problem isn't setting up Wiki, is only to fill up it.
If you want, infos on Harbour mailing lists is here : http://www.harbour-project.org/faq/harbour34.html#34
( Warning : some infos may be obsolete )
Regards
--
esgici
Viva INTERNATIONAL HMG
-
- Posts: 119
- Joined: Wed Feb 18, 2009 2:14 pm
Re: List to Array
esgici,
Concerning the Wiki, no problem sir.
>> HMG docs are perfect, samples also. Complete, short, concentrated, easy to understand and effective.
Yes I agree sir. Please let me offer great compliments on the teams efforts there. Great job!
Like you I want HMG not only to survive but be realized for just how good a development tool it is. Though you and I are long time Clipper guys I think presenting HMG in a way that makes it appear like a new (yet very mature) alternative to Java and .Net might be useful in many demographics.
The history of Clipper is like a tragic hero story. It was so good it evolved into a virtual religion. When it left Nantucket it started a downward spiral in the USA that never really recovered. HMG is the phoenix risen!
This sounds like I'm nuts but for anyone starting out in Clipper then having to write as much Visual Basic and Java as I have it was like getting used to being in a jail cell in comparison. The marketing efforts behind VB\Java overwhelmed common sense and practicality. Yep I am well off topic here...sorry.
Michael
Concerning the Wiki, no problem sir.
>> HMG docs are perfect, samples also. Complete, short, concentrated, easy to understand and effective.
Yes I agree sir. Please let me offer great compliments on the teams efforts there. Great job!
Like you I want HMG not only to survive but be realized for just how good a development tool it is. Though you and I are long time Clipper guys I think presenting HMG in a way that makes it appear like a new (yet very mature) alternative to Java and .Net might be useful in many demographics.
The history of Clipper is like a tragic hero story. It was so good it evolved into a virtual religion. When it left Nantucket it started a downward spiral in the USA that never really recovered. HMG is the phoenix risen!
This sounds like I'm nuts but for anyone starting out in Clipper then having to write as much Visual Basic and Java as I have it was like getting used to being in a jail cell in comparison. The marketing efforts behind VB\Java overwhelmed common sense and practicality. Yep I am well off topic here...sorry.
Michael