On Tue, 04 Apr 2000, [EMAIL PROTECTED] wrote:
> 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 ' '
> ms: 0
> str: "my+name+is+tim"
> pairs: 0
> forall str
> [
> if same? first str "m"
> [ms: ms+ 1]
> if same? first str "+"
> [change str #" "]
> ]
> print ["ms: " ms]
> str: head str
> print str
>
> ;The preceding code obviously doesn't work.
> what am I doing wrong.
> TIA
> Tim
Tim,
Here is a working version with these changes:
if same? first str "m" is now if str/1 = #"m"
change str #" " is now str/1: #" "
REBOL [
Purpose: {example count every occurance of 'm'
change every occurance of '+' to ' '}
]
ms: 0
str: "my+name+is+tim"
forall str [
if str/1 = #"m" [ ms: ms + 1 ]
if str/1 = #"+" [ str/1: #" " ]
]
str: head str
print ["ms: " ms]
print str
-Karl