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.
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.