-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 05, 2000 7:24 AM
To: [EMAIL PROTECTED]
Subject: [REBOL] [REBOL]Evaluating characters in a string Re:


>instead of "same?" use "equal?" and use "#" in
>single character tests.  This works:
>ms: 0
>str: "my+name+is+tim"
>
>forall str
>[
>  if equal? first str #"m"
>    [ms: ms + 1]
>  if equal? first str #"+"
>    [change str #" "]
>]
>print ["ms: " ms]
>str: head str
>print str
>

; Yep, although I always use the '= word:
forall str [if #"m" = first str [ms: ms + 1]]

; I really don't like 'forall because it changes the index.
; I try to use 'parse where ever I can (just because it's there):
parse str [any[thru "m" (ms: ms + 1)]]

; The "change each occurance" of an element is a no-brainer (I just recently
found this command). This also works with multiple elements (instead of "m"
you could replace "my", for instance).
replace/all str "m" " "

>>> <[EMAIL PROTECTED]> 04/05 12:36 AM >>>
>>>Hello All:
>>>I want to search each element in a string.
>>>I want to count occurances of some elements
>>>and change other elements
>>>
>>>;example count every occurance of 'm'
>>>;  change every occurance of '+' to ' '

- Michael Jelinek

Reply via email to