Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: to-char

From: carl:cybercraft at: 11-Feb-2002 17:47

On 11-Feb-02, [Izkata--aol--com] wrote:
> sorry, I'm not used to the harder stuff like > parsing, yadda, yadda, yadda. > What I'm looking for is a function/native that > will change a word into a block of characters, > for example: > tochar "Hello" > Word: [ > H > e > l > l > o > ]
Hi Daniel, I notice Brett has just posted similar stuff to the following, but this is what I came up with anyway... This function should do what you want... to-chars: func [str /local word][ word: copy [] forall str [append word str/1] word ]
>> to-chars "hello"
== [#"h" #"e" #"l" #"l" #"o"]
>> to-chars "goodbye"
== [#"g" #"o" #"o" #"d" #"b" #"y" #"e"] However, depending on what you're doing, you may be able to get the results you want without needing to convert a string to a block, as a string is already a series of characters. So, the following gives the same results...
>> str: "hello"
== "hello"
>> str/2
== #"e"
>> word: to-chars str
== [#"h" #"e" #"l" #"l" #"o"]
>> word/2
== #"e" HTH. -- Carl Read