[REBOL] [REBOL]string to series function Re:(2)

2000-04-11 Thread tjohnson

Sterling showed me how the following code
gives me a block
 parse "one#two%three four" "#%"
== ["one" "two" "three" "four"]

that's great! Now if I write:
my-series: parse "one#two%three four" "#%"
just-one: my-series/1
just-one is returned as "one"

now how do I get "one" into just-one with 1 line
of code instead of two?

thanks again
tim





[REBOL] [REBOL]string to series function Re:(2)

2000-04-10 Thread icimjs

Hi Sterling,

one little detail: your approach works well enough with this particular
example because space is one of the desired delimiters.

Conceivably Tim may want a more universal solution that enables him to
determine whether or not he wants to include spaces in his parse rule. In
that case IMHO it would be more appropriate to use parse's all refinement
and - for the sake of this particular example - include space explicitly as
a delimiter in the rule:

With space:
 parse/all "one#two%three four" "%# "
== ["one" "two" "three" "four"]

Without space
 parse/all "one#two%three four" "%#"
== ["one" "two" "three four"]

Note that the second version returns "three four" as one string because
space is not included in the rule.

At 09:06 PM 4/10/00 -0700, you wrote:

You really ought to just try these things. ;)
You'll be surprised at what you find.

 parse "one#two%three four" "#%"
== ["one" "two" "three" "four"]
 

Sterling

 I would like to have a function to do
 the following
 1)take two strings as arguments
   a)arg one is source
   b) arg two is delimiters
 2)return a series
 
 it would work like this:
 
 my-series: string-to-series "one#two%three four" "#% "
 my-series is returned as ["one" "two" "three" "four"]
 
 BTW: I have a c function that does this. With
 subsequent function calls, it is about 40 lines of
 code. I'm pretty lost when it comes to parse, but
 I bet the rebol function would be shorter.
 thanks
 tim




;- Elan  [: - )]




[REBOL] [REBOL]string to series function Re:(2)

2000-04-10 Thread tjohnson

Sterling:
Wow!! That's just what I wanted. 
tj
At 09:06 PM 4/10/00 -0700, you wrote:

You really ought to just try these things. ;)
You'll be surprised at what you find.

 parse "one#two%three four" "#%"
== ["one" "two" "three" "four"]
 

Sterling

 I would like to have a function to do
 the following
 1)take two strings as arguments
   a)arg one is source
   b) arg two is delimiters
 2)return a series
 
 it would work like this:
 
 my-series: string-to-series "one#two%three four" "#% "
 my-series is returned as ["one" "two" "three" "four"]
 
 BTW: I have a c function that does this. With
 subsequent function calls, it is about 40 lines of
 code. I'm pretty lost when it comes to parse, but
 I bet the rebol function would be shorter.
 thanks
 tim