Re: Capitalize string

2009-03-09 Thread Tom Faulhaber

cl-format has this built-in:

(cl-format nil ~:(~a~) the quick brown fox) - The Quick Brown
Fox

Tom

On Mar 8, 10:48 am, christophe turle ctu...@yahoo.com wrote:
 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 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  ) ))

 ;;; (capitalize ab) - Ab
 ;;; (capitalize c) - C
 ;;; (capitalize ) - 
 ;;; (def s ab)
 (defn capitalize [s]
   (if (.isEmpty s)
     
     (str (.toUpperCase (.substring s 0 1))
          (.toLowerCase (.substring s 1)) )))

 ;;; (words-string '(A Bc)) - A Bc
 ;;; (words-string '()) - 
 (defn words-string [words]
   (apply str (interpose   words)) )
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 da...@bosatsu.net wrote:

 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 message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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)) ?

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)))


--
Itay Maman
http://javadots.blogspot.com

On Mar 8, 3:20 pm, David Sletten da...@bosatsu.net wrote:
 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
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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]
  (let [words (.split words  )
words (for [[w  ord] words] (apply str (.toUpperCase (str  
w)) ord))]

(apply str (interpose   words

Clojure= (capitalize ab   cd)
Ab   Cd

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Capitalize string

2009-03-08 Thread Stuart Sierra

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
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---