AltME: Parse


parse/all #{010203} [thru #{03} (print ".")] ;works on R3 and Red but fails on R2, any workaround for this?
There is no refinement all. Leave that out and the output is like the output for R3 with all refinement.
Arnold, there is /all refinement in R2.
parse/all  to-string #{010203}  compose [thru (to-string #{03})  ([(print ".")]) ]
So is the only workaround parsing binary! is converting to string!?
Although this one works, it looks parsing with binary! works but TO / THRU doesn't.
R2> parse/all #{010203} [#{010203}]
== true
Sorry I only use a Red version from before the libRed changes.  that is why I got the message
red>> parse/all #{010203} [thru #{03} (print ".")]
*** Script Error: parse has no refinement called all
*** Where: parse
Sure, there is no /all in Red, it is default. I meant the difference of TO with binary!.
Using a char! or string! as matching target works on R2:
parse/all #{010203} [thru #"^(03)" (print ".")]
parse/all #{010203} [thru "^(03)" (print ".")]
You can also use AS-STRING instead of TO-STRING so that there is no conversion really going on.
>> bin: #{010203}
== #{010203}
>> str: as-string bin
== "^A^B^C"
>> append str "A"
== {^A^B^CA}
>> bin
== #{01020341}

Thank you all, using char/string or as-string looks good solutions.

I need to parse the following string "5.1+2+1" to split the single numeric values (REBOL2 here)
I use the following code:
data: "5.1+2+1"
parse data [some [copy percentuale some cs (print ["Percentuale" percentuale])  to   ["+"  | none] skip] to end]
and I get an error :
** Script Error: Invalid argument: + | none
** Near: parse data [some [copy percentuale some cs (print ["Percentuale" percentuale]) to ["+" | none] skip] to end]
While this works:
data: "5.1+2+1"
parse data [some [copy percentuale some cs (print ["Percentuale" percentuale])  to   "+"  | none skip] to end]
Percentuale 5.1
Percentuale 2
Percentuale 1
Seems <to [ "+" | none]> is not allowed but  <to   "+"  | none> is !
Also, if I use END in palce of NONE :
data: "5.1+2+1"
parse data [some [copy percentuale some cs (print ["Percentuale" percentuale])  to   "+"  | END skip] ]
I get only:
Percentuale 5.1
Given the special, simple case of splitting a string on a single character, you could use this simpler form:
    data: "5.1+2+1"
    == "5.1+2+1"
    parse data "+"
    == ["5.1" "2" "1"]
"+" could be "+" or "-"
And later I need to store the sign

Hi, Giuseppe. You correctly concluded that to ["+" | none] is not allowed in the Parse dialect at present. If it were allowed, it would still not be what you want, I guess. Don't you want something like to "+" | to end ?
... or maybe to "+" | skip to end to eliminate the "already at end" case
... if you want to eliminate it
BTW, your some cs code is not understandable, unless you show how it is defined
cs: charset ["." #"0" - #"9"]
I forgot to write it !
My goal is to extract the each  % , buil a block with them and then calculate the overall value when applied to a number
5.1%+2%+2% of 150
I need to calculate
Total: V1+V2+V3
The concatenated percentag are taken from a DB and they are without the percentage sign and as STRING VALUE.

I  guess you already solve it, but a first step is :

Last message posted 149 weeks ago.