Page 1 of 1

Extracting the lines from a text

PostPosted: Thu Sep 22, 2022 6:17 am
by Antonio Linares
Very nice code, thanks to José M.C. Quintas:

aList := hb_RegExSplit( hb_Eol(), cText )

Re: Extracting the lines from a text

PostPosted: Thu Sep 22, 2022 6:21 am
by Antonio Linares
Another way:

hb_ATokens( cText, hb_Eol() )

Re: Extracting the lines from a text

PostPosted: Thu Sep 22, 2022 6:57 am
by hua
Thanks for the tip of using hb_regexSplit().
However hb_atokens() only accepts a single character for the delimiter.
So can't pass CRLF to it

Re: Extracting the lines from a text

PostPosted: Mon Sep 26, 2022 3:50 am
by Jimmy
hi,
hua wrote:However hb_atokens() only accepts a single character for the delimiter.
So can't pass CRLF to it


https://github.com/Petewg/harbour-core/wiki/hb_A#hb_atokenscstring-cdelimiterleol-lskipstrings-ldoublequoteonly--atokens
hb_ATokens(<cString>, [<cDelimiter>|lEOL], [<lSkipStrings>], [<lDoubleQuoteOnly>]) ➜ aTokens

returns an array filled with all individual tokens of given <cString> string, that is, all the separate sub-strings that are delimited by either <cDelimiter> or by EOL (end of line) if (instead of <cDelimiter>) <lEOL> has been passed and evaluates to .T.
If neither <cDelimiter> nor <lEOL> specified, then as delimiter is used, by default, an empty space (ASCII char 32).

Re: Extracting the lines from a text

PostPosted: Mon Sep 26, 2022 7:00 am
by hua
Thanks Jimmy.
Seems Harbour's documentation is a bit different than what I got from xHarbour Language Reference 1.1
HB_ATokens( <cString> , ;
[<cDelimiter>] , ;
[<lSkipQuotes>] , ;
[<lDoubleQuotesOnly>] ) --> aTokens

<cDelimiter>
A single character can be specified as delimiter used to tokenize the string <cString>. It defaults to a blank space (Chr(32)).