[REBOL] Re: uppercase two letters?
From: Al::Bri::xtra::co::nz at: 26-Apr-2003 11:18
> All I want to do is squash a sentence, then make the first and third
letters uppercase.
> like this:
>
> "this is a line" ==> "thisisaline" ==> "ThIsisaline"
>> S: "this is a line"
== "this is a line"
>> Squash: map s func [C [char!]] [if C <> #" " [C]]
== "thisisaline"
>> Squash/1: to-char uppercase to-string Squash/1
== "Thisisaline"
>> Squash/3: to-char uppercase to-string Squash/3
== "ThIsisaline"
Or, if you have Rebol/Core 2.5.5:
>> source remove-each
remove-each: native [
{Removes a value from a series for each block that returns TRUE.}
'word [get-word! word! block!] {Word or block of words to set each time
(will be local)}
data [series!] "The series to traverse"
body [block!] "Block to evaluate. Return TRUE to remove."
]
>> S: "this is a line"
== "this is a line"
>> remove-each C S [C = #" "]
== "thisisaline"
>> s
== "thisisaline"
>> S/1: to-char uppercase to-string S/1
== "Thisisaline"
>> S/3: to-char uppercase to-string S/3
== "ThIsisaline"
>> s
== "ThIsisaline"
I hope that helps!
Andrew Martin
ICQ: 26227169 http://Valley.WebPictureBook.com/
-><-
>> source map
map: func [
{Maps or applies the function to all elements of the series.} [catch]
Arg1 [any-function! series!]
Arg2 [any-function! series!]
/Only "Inserts the result of the function as a series."
/Full "Doesn't ignore none! values." /local
Result Results Function Series][
throw-on-error [
any [
all [
any-function? :Arg1 series? :Arg2
(Function: :Arg1 Series: :Arg2)
]
all [
any-function? :Arg2 series? :Arg1
(Function: :Arg2 Series: :Arg1)
]
throw make error! reduce [
'script 'cannot-use rejoin [
{"} mold 'Map " " mold type? :Arg1 {"}
]
rejoin [
{"} mold type? :Arg2 {"}
]
]
]
Results: make Series length? Series
do compose/deep [
foreach [(Arguments :Function)] Series [
if (
either Full [
compose [not unset? set/any 'Result Function
(Arguments :Function)]
] [
compose/deep [
all [
not unset? set/any 'Result Function
(Arguments :Function)
not none? Result
]
]
]
)
[
(either Only ['insert/only] ['insert]) tail Results
:Result
]
]
]
Results
]
]
>> source arguments
arguments: func [
"Returns the arguments of the function as a block."
F [any-function!] /local
Arguments][
Arguments: make block! 2
foreach Argument pick :F 1 [
if refinement? :Argument [
break
]
append Arguments :Argument
]
Arguments
]