Re: String parsing?
On Oct 25, 2005, at 2:32 PM, Michael Zanis wrote:
Hi,
I am new to ruby but have an okay background in perl. I am trying
to parse
a string into an array.
string = (foo:0.05,bar:0.115);
I would like the array to look like this:
Array[0] = (
Array[1] = foo
Array[2] = 0.05
Array[3] = ,
Array[4] = bar
Array[5] = 0.115
Array[6] = )
Array[7] = ;
See if this helps:
>> "(foo:0.05,bar:0.115);".scan(/[a-z]+|\d+\.\d+|[(,);]/)
=> ["(", "foo", "0.05", ",", "bar", "0.115", ")", ";"]
James Edward Gray II
.
Relevant Pages
- Re: Returning a string array from a function
... I'd like to return an string array from a function so ... E.g. "total" only gets found out inside foo. ... to avoid storing past the end of the sptr[] array if `total' ... (comp.lang.c) - Re: dynamic array of ints
... >need to parse them out and put them in an array. ... >are there and thus don't know how large to make my array. ... >number of ints and then allocate memory based on that. ... >sure what to use to read the ints from the string. ... (comp.programming) - Re: why doesnt this compile
... Above, foo return array, but s is just a string. ... Private foo1() As String ... (microsoft.public.vb.general.discussion) - Re: Parsing Data, Storing into an array, Infinite Backslashes
... > I am using this function to parse data I have stored in an array. ... It looks like you are setting the variable qval to the string ... Hint: it ... (comp.lang.python) - String parsing?
... I am new to ruby but have an okay background in perl. ... I would like the array to look like this: ... I might see if there is an elegant way to parse this string using tokens. ... (comp.lang.ruby) |
|