Is there a function that directly converts a memo string to an array?

149 views
Skip to first unread message

HBQuerier

unread,
Sep 20, 2022, 7:10:47 PM9/20/22
to Harbour Users
Hi,

If we have a string with a list of items delimited by carriage returns and line feeds, is there a function that directly converts it to an array?

Or do we need to parse the string out, as with other delimited strings?


Mario H. Sabado

unread,
Sep 20, 2022, 8:38:41 PM9/20/22
to 'elch' via Harbour Users
Hi,

HB_aTokens() and use HB_EoL() as separator?

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/00361adf-ac70-4bcb-b6d0-bc1163ebccdbn%40googlegroups.com.

Clippero

unread,
Sep 21, 2022, 8:18:02 AM9/21/22
to Harbour Users
_cantlin := MLCOUNT(_varmemo)
Alin:= {}
FOR i := 1 TO _cantlin
    AADD(Alin,MEMOLINE(_varmemo,,i)
NEXT i

HBQuerier

unread,
Sep 21, 2022, 8:49:47 AM9/21/22
to Harbour Users
Yes, that's one way.  But I was wondering if there was something like MemoTran, but that transforms the string into an array, rather than a semicolon-separated list.

HBQuerier

unread,
Sep 21, 2022, 8:50:52 AM9/21/22
to Harbour Users
Yep, I'll use something like this, thanks.

It looks like there's no direct function to do the transformation, similar to the way MemoTran converts the string into an equivalent delimited list.

José M. C. Quintas

unread,
Sep 21, 2022, 9:23:24 AM9/21/22
to harbou...@googlegroups.com

Not sure, try this:

aList := hb_RegExSplit( hb_Eol(), cText )


José M. C. Quintas

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

HBQuerier

unread,
Sep 21, 2022, 10:14:45 AM9/21/22
to Harbour Users
Looks workable, thanks  José.

Francesco Perillo

unread,
Sep 21, 2022, 10:55:26 AM9/21/22
to harbou...@googlegroups.com
using memoline is ok but very inefficient

Actually there is a function and it was already proposed: hb_atokens()

I've been using it since years:
One sample:
   c := memoread( cFile )
   c := strtran( c, chr(10),
"" )
   a := hb_atokens( c, chr( 13 ) )

Another sample:
c := memoread( "input.txt" )
a := hb_atokens( c, chr(13)+chr(10) )

It depends on the source file, if it a linux or windows text file

Looking at the source code I now see that there is a third parameter, a numeric flag, for "quoting strings" and EOL... but I have no time now to understand better.



Pete

unread,
Sep 21, 2022, 11:45:20 AM9/21/22
to Harbour Users
Yes! the function you are looking for,  has already been suggested (by mhsabado and fperillo)
and this is no other than hb_Atokens()

In your case,  just invoke it like below:
aArray := hb_ATokens( cString, .T. )

For more please look here and here.

regards,
Pete

Bernard Mouille

unread,
Sep 23, 2022, 12:36:51 PM9/23/22
to Harbour Users
Hello,
You can try the attached code if tou want to convert memo fields of a table to an array multi.
Regards,
Bernard.




Test.txt
Reply all
Reply to author
Forward
0 new messages