parsingrebolrebol2

Rebol: how to split a string into characters


Using Rebol how do I split this string into characters (without using a c-like approach with loops)? I'm using version 2.7.8.2.5 which does not have the split method.

str: "Today is Monday"

I want to split the above into:

[ 'T' 'o' 'd' 'a' 'y' ' ' 'i' 's' ' ' 'M' 'o' 'n' 'd' 'a' 'y']

Parse method seems to only split a sentence into constituent words.

Thank you.


Solution

  • If you don't want to use loops, there's one nifty trick:

    >> head extract/into str 1 []  
    == [#"T" #"o" #"d" #"a" #"y" #" " #"i" #"s" #" " #"M" #"o" #"n" #"d" #"a" #"y"]
    

    OTOH, string! is already a series of char! values, so breaking it up into characters like that doesn't provide any clear benefit.