uppercase two letters?
[1/9] from: tofo:695online at: 25-Apr-2003 17:23
Hi Guys,
you wouldn't believe how ugly my attempts at this have been!
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"
If you wish to go blind, I'll post my attempt (please don't make me!)
tanks.
--
signature to telemarketer: "click"
-tom
[2/9] from: greggirwin:mindspring at: 25-Apr-2003 17:01
Hi Tom,
TF> you wouldn't believe how ugly my attempts at this have been!
TF> all I want to do is squash a sentence, then make the first and third
TF> letters uppercase.
Well, let's see, we could start by writing a function to handle the
general case, like so:
uppercase-at: func [
"Changes the letters at the specified positions to uppercase"
string positions [any-block!]
] [
foreach pos positions [
poke string pos to char! uppercase to string! pick string pos
]
]
Then use it like this:
>> s: copy "this is a line"
== "this is a line"
>> uppercase-at replace/all s " " "" [1 3]
Does that work for you?
-- Gregg
[3/9] 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
]
[4/9] from: tofo:695online at: 26-Apr-2003 2:39
On Fri, Apr 25, 2003 at 05:01:43PM -0600, Gregg Irwin wrote:
> Hi Tom,
> TF> you wouldn't believe how ugly my attempts at this have been!
<<quoted lines omitted: 15>>
> >> uppercase-at replace/all s " " "" [1 3]
> Does that work for you?
:-)
You and Andrew inspired me to try again. How about this?
squashit: func [line [string!]] [
trim/all lowercase line
poke line 1 to-char uppercase to-string line/1
poke line 3 to-char uppercase to-string line/3
]
I've been a rebol novice for too long! Someone else commented
recently on how difficult it seems to be to move beyond simple to
advanced. Every script I try seems to center around "foreach" and
rejoin
. I can tell by reading this list that there's more to life...
if my function is ok, poke is what I needed.
thanks.
--
signature mischievous: "heh, heh, heh"
-tom
[5/9] from: tomc:darkwing:uoregon at: 26-Apr-2003 0:29
not using anything fancy
>> l1: "this is a line"
== "this is a line"
>> l2: rejoin parse l1 none
== "thisisaline"
>> if l2/1 > 90 [change l2 (l2/1 - 32)]
== "hisisaline"
>> l2
== "Thisisaline"
>> l2: next next l2
== "isisaline"
>> if l2/1 > 90 [change l2 (l2/1 - 32)]
== "sisaline"
>> l2: head l2
== "ThIsisaline"
On Fri, 25 Apr 2003, Tom Foster wrote:
[6/9] from: g:santilli:tiscalinet:it at: 26-Apr-2003 10:32
Hi Tom,
On Friday, April 25, 2003, 11:23:39 PM, you wrote:
TF> "this is a line" ==>> "thisisaline" ==> "ThIsisaline"
>> s: "this is a line"
== "this is a line"
>> trim/all s
== "thisisaline"
>> uppercase/part s 1
== "Thisisaline"
>> uppercase/part skip s 2 1
== "Isisaline"
>> s
== "ThIsisaline"
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[7/9] from: greggirwin:mindspring at: 26-Apr-2003 11:51
Hi Gabriele,
I love how a seemingly simple question leads to so many solutions and
makes me remember that I always forget things. :)
In this case, I had forgotten the /part refinement for uppercase and I
hadn't thought about TRIM, which is native and should be much faster
than REPLACE.
Thanks!
-- Gregg
[8/9] from: Al:Bri:xtra at: 27-Apr-2003 8:57
Me, too!
Andrew Martin
ICQ: 26227169 http://Valley.WebPictureBook.com/
[9/9] from: tofo:695online at: 26-Apr-2003 21:35
On Sun, Apr 27, 2003 at 08:57:06AM +1200, Andrew Martin wrote:
> Me, too!
>
Me, three. I got the thing I was working on, well, working. I
recently discovered emacs wiki mode, and was playing around with it.
I over-used rejoin, and am sure that this is otherwise pretty ugly in
general, but if anybody feels like commenting, I'd be happy...
oh yeah, there has to be a file, project-name.txt, in base-dir with contents something
like
this
that
One thing
another thing
REBOL [
Title: "myewiki2"
Date: 26-Apr-2003
File: %myewiki2.r
Purpose: "another attempt at my own ewiki outline maker"
RCS-id: "$Id: myewiki2.r,v 1.5 2003/04/27 01:25:56 tf Exp $"
]
home-dir: to-file "~/"
base-dir: %ewikis/
project-name: ask "project name: "
project-dir: to-file rejoin [
home-dir base-dir project-name "/"
]
if not exists? base-dir [make-dir base-dir]
if not exists? project-dir [make-dir project-dir]
file-top: trim/head {
-*- emacs-wiki -*-
PrOjectindex
}
squashit: func [line [string!]] [
;wikiword-ize...
trim/all lowercase line
poke line 1 to-char uppercase to-string line/1
poke line 3 to-char uppercase to-string line/3
]
file: to-file rejoin [home-dir base-dir project-name ".txt"]
;call/wait rejoin ["xjed " file]
blk: []
foreach line read/lines file [
line-untouched: copy line
project-file: to-file rejoin [project-dir squashit line]
; if not exists? project-file [close open/new project-file]
if not exists? project-file [write project-file rejoin [file-top "_" line-untouched "_"
newline newline]
]
repend blk rejoin [line-untouched " ==> " line newline]
]
write to-file rejoin [project-dir "PrOjectindex"] rejoin [file-top blk]
; --
; signature to baby: "doobywoobybooboo"
; -tom
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted