Hi,

what are the tools available from easier text extraction?

The input is unstructured text, but I want to extract portion from it.

I am not looking for an engineered approach (writing a parser or something), 
but something that can be done quickly by hand (i.e. interactively).

For example I have string
str = ' Temperature 0           37C (98F) [0x25] (TMPIN0)'
Now I want to extract '0x25' from it and convert it into integer

In Ruby it is dead simple:
str[/\[(.*)\]/,1].hex # "=> 37" , or .to_i(16)

In Pharo I have to break my fingers first:
rx := '.*\[0x(.*)\].*' asRegex.
rx matches: str.
Integer readFrom: (rx subexpression: 2) base: 16 "=>37".

* I have to know that to get subexpression I have to match first to manipulate 
the internal state
* I have to store the matcher to access the subexpression
* I need to explicitly use some global variable Integer as a conversion utility 
to convert hex to dec
* I have to manually remove the 0x, even though it is a very common way of 
expressing hex numbers


So the question is:
do we have a better way to do these things? And as I've mentioned - the use 
case is interactive coding where you often throw the code away when you are 
done; so dead easy to write and use.

Thanks,
Peter


Reply via email to