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 20:54

Hi Guys, I have integrated the suggestions of Andrew, and this is the end-result. Time to give this one a rest, and move on to more daunting stuff (anyone done that XML-to-HTML-using-stylesheets thingie yet?). REBOL [ Title: "Counting chars in a string" File: %count-char.r Date: 16-November-2000 Purpose: { To count the number of occurences of each character in a string. } Usage: {count-char string!} Notes: { Implemented after some very useful suggestions by the REBOL mailing list people. Thanx guys! } History: [ 16-November-2000 "A version I can live with!" ] ] count-char: function [ { This function counts the number of occurrences of each character in string str, and returns a printable block with the results. } str [string!] ][ count look ][ count: make block! 0 foreach char str [ either found? look: find count char [ change (next look) ((second look) + 1) ][ append count reduce [char 1 "^/"] ] ] return count ] Bard