Re: Is there a way of reading a sequence from a variable?
- Posted by DerekParnell (admin) Apr 17, 2012
- 1247 views
What I want to read is any Eu object - eg "\"Hello\"".
That is given something like:
"\"alpha\" = 3.456"
I can read out "alpha",
drop the white space
see I've got '=',
drop it and any white space following,
then read out the value (which culd be any Eu object),
checking at the end I've consumed the whole string.
Sort of get() for strings, or
Poor man's parsing.
Thanks
I see, so it's not that value() can't do quoted strings, but that you want to parse a string, one 'token' at a time.
There are a number of ways to do this. Jim has mentioned one way with using GET_LONG_ANSWER and value().
You could also use the keyvalues() function found in std/text.e or the split() function found in std/sequence.e
include std/text.e sequence text = "\"alpha\" = 3.456" sequence result result = keyvalues(text)
gives ...
{{"alpha","3.456"}}Which is a lot easier to parse now.
Or using split() ...
include std/sequence.e sequence text = "\"alpha\" = 3.456" sequence result result = split(text,,1)
which gives ...
{"\"alpha\"","=","3.456"}which is also easy to parse now.