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

[REBOL] Re: count characters. (Was: Simple things should be simple to do ?)

From: tooki:widebay:au at: 16-Nov-2000 15:27

Hi All, I've found the answer to my own question:
> One thing though: isn't there a more elegant way of doing the > append(append(append count char) 1) "^/") stuff?
Turns out you can do: append count reduce [char 1 "^/"] with the same result. The whole code now reads: count-char: func [ str [string!] /local count look ][ count: make block! 0 foreach char str [ either look: find count char [ change (next look) ((second look) + 1) ][ append count reduce [char 1 "^/"] ] ] print count ] It does do the trick:
>> count-char "aaabbbccddddddd"
a 3 b 3 c 2 d 7 So, let's see if anyone else comes up with even more elegant solutions. I love to see other people's code. The ideas some people come up with never stop to astound and delight me. Bard