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 ***
>
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
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
--~--~-
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
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]
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
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
--~--~
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
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