Em 12 de novembro de 2016, Jack escreveu:
On Sun, 11 Dec 2016, Allin Cottrell wrote:
I'm wondering whether people would consider this function (which I'm
> calling "strscrape" for now) worth having: it takes a string argument and
> returns a row vector containing any numerical values encountered in the
> string (or an empty matrix if none are found). There's a test version in
> git but it's not documented; I'm not committed to keeping it if doesn't
> attract much support.
>
I, for one, quite like it.
Me too. It could help apply web scrapping tasks using Gretl!
Unlike using sscanf() to retrieve a matrix, the idea with this
function is
> that the numbers may be embedded in arbitrary text. Numbers are identified
> as starting with either a minus sign (followed directly by a digit) or a
> digit, and their length in characters is decided by the C function strtod
> (so scientific notation is acceptable). As the function stands, the decimal
> character is unconditionally '.'.
>
Now, how could I EVER object to THIS? ;)
Of course some rough edges will have to be dealt with. For example, the
output to
a = strscrape("1.2.3")
is, as of now,
[1.2, 3]
which of course makes sense but is only one of the possible conventions.
To avoid that kind of situation I suggest to return the number as a array
of strings. So the user can explicit choose what to do. Furthermore, using
array of strings as the return value of the function can help users to
handle the "problem" of decimal comma.
One more thing: it would be great if we could have a function like this to
count the number of occurrences of a determined string. Something like this:
string S = "I like Gretl because Gretl is great and Gretl is complete"
scalar N = strscrapec(S, "Gretl") # strscrapc; String scrape counter
# result: N = 3
Best regards,
Henrique Andrade