) -
;;; (def s ab c)
(defn my-capitalize [s]
(words-string (map capitalize (string-words s))) )
;;; *** libraries code ***
;;; (string-words ) - []
;;; (string-words ab) - [ab]
;;; (string-words ab c) - [ab c]
(defn string-words [s]
(if (.isEmpty s)
[]
(.split s
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
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 da...@bosatsu.net wrote:
Is there a function to capitalize the first letter of a string or a
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
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))
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]
On Mar 8, 9:39 am, David Sletten da...@bosatsu.net 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