Re: Capitalize string

2009-03-09 Thread Tom Faulhaber
quot;Ab C" > ;;; (my-capitalize "ab") -> "Ab" > ;;; (my-capitalize "") -> "" > ;;; (def s "ab c") > (defn my-capitalize [s] >   (words->string (map capitalize (string->words s))) ) > > ;;; *** libraries code *** >

Re: Capitalize string

2009-03-08 Thread christophe turle
my try : ;;; *** application code *** ;;; (my-capitalize "ab c") -> "Ab C" ;;; (my-capitalize "ab") -> "Ab" ;;; (my-capitalize "") -> "" ;;; (def s "ab c") (defn my-capitalize [s] (words->string (map

Re: Capitalize string

2009-03-08 Thread Stuart Sierra
On Mar 8, 9:39 am, David Sletten wrote: > Is there a function to capitalize the first letter of a string or a   > better way than this idiotic code? Once again, Apache Commons to the rescue: http://tinyurl.com/d38wwq (StringUtils/capitalize "clojure") ;;=> "Clojure" -Stuart Sierra --~--~-

Re: Capitalize string

2009-03-08 Thread Chouser
On Sun, Mar 8, 2009 at 9:26 AM, Itay Maman wrote: > > What's the shortest way for capitalizing the first letter of every > word, i.e.: (assert (= (capitalize "ab cd") "Ab Cd")) ? (use '[clojure.contrib.str-utils :only (re-gsub)]) (defn capitalize [s] (re-gsub #"\b." #(.toUpperCase %) s)) --C

Re: Capitalize string

2009-03-08 Thread Meikel Brandmeyer
Hi, Am 08.03.2009 um 15:26 schrieb Itay Maman: (assert (= (capitalize "ab cd") "Ab Cd")) ? Here's my take: (defn capitalize [s] (apply str (map (fn [prev curr] (or (and (= prev \space) (Character/toUpperCase curr)) curr)) (cons \space s) s))) That's mine: (defn capitalize [words]

Re: Capitalize string

2009-03-08 Thread Itay Maman
I am not particularly fond of idiomatic style. In production code I want something clear and explicit even if it is a bit longer. That said, your question triggered this challenge: What's the shortest way for capitalizing the first letter of every word, i.e.: (assert (= (capitalize "ab cd") "Ab Cd

Re: Capitalize string

2009-03-08 Thread David Sletten
On Mar 8, 2009, at 2:45 AM, Joshua Fox wrote: > > How about this? > user=> (defn upper-first [s] (apply str (Character/toUpperCase (first > s)) (rest s))) > #'user/upper-first > user=> (upper-first "a") > "A" > That certainly qualifies as less idiotic. :) Mahalo, David Sletten --~--~

Re: Capitalize string

2009-03-08 Thread Joshua Fox
How about this? user=> (defn upper-first [s] (apply str (Character/toUpperCase (first s)) (rest s))) #'user/upper-first user=> (upper-first "a") "A" On Sun, Mar 8, 2009 at 3:39 PM, David Sletten wrote: > > Is there a function to capitalize the first letter of a string or a > better way t

Capitalize string

2009-03-08 Thread David Sletten
Is there a function to capitalize the first letter of a string or a better way than this idiotic code? (apply str (map #(if (zero? %2) (Character/toUpperCase %1) %1) "clojuriffic" (iterate inc 0))) Aloha, David Sletten --~--~-~--~~~---~--~~ You received this m