Hi all!

Larry asked:
> > How would I parse such that
> > 
> > ThisIsTheLine
> > 
> > 
> > would result in:
> > 
> > This Is The Line.
> 

Using parse, try this ...

the-line: "ThisIsTheLine"
big-alpha: charset [#"A" - #"Z"]
tmp: none
parse/all/case the-line [
    skip  ; Skip the first character
    any [to big-alpha tmp: skip (insert tmp " ")]
    to end  ; Not really needed here
]
print the-line


Andrew answered:
> I know, it doesn't use 'parse, but this way was more obvious...
> 
> [
> REBOL [
>  ]
> 
> Line: "ThisIsTheLine"
> 
> Split: function [Line [string!]] [Result] [
>  Result: make string! 0
>  foreach C Line [
>   if any [
>    C == #"A"
>    C == #"B"
>    C == #"C"
>    C == #"D"
>    C == #"E"
>    C == #"F"
>    C == #"G"
>    C == #"H"
>    C == #"I"
>    C == #"J"
>    C == #"K"
>    C == #"L"
>    C == #"M"
>    C == #"N"
>    C == #"O"
>    C == #"P"
>    C == #"Q"
>    C == #"R"
>    C == #"S"
>    C == #"T"
>    C == #"U"
>    C == #"V"
>    C == #"W"
>    C == #"X"
>    C == #"Y"
>    C == #"Z"
>    ] [
>    if not empty? Result [
>     append Result " "
>     ]
>    ]
>   append Result C
>   ]
>  Result
>  ]
> 
> print Split Line
> 
> ]
> 
> >> do %line.r
> This Is The Line

Procedurally, try this ...

the-line: "ThisIsTheLine"
tmp: next the-line
forall tmp [
    if find/case "ABCDEFGHIJKLMNOPQRSTUVWXYZ" first tmp [
        tmp: insert tmp " "
    ]
]
print the-line

... or this (faster) ...

the-line: "ThisIsTheLine"
big-alpha: charset [#"A" - #"Z"]
tmp: the-line
while [tmp: find/case next tmp big-alpha] [tmp: insert tmp " "]
print the-line


Do these help?
--
Brian Hawley

Reply via email to