Monday, May 2, 2016

How to create short abreviation from long string by using Clojure and regular expressions

(ns clojure.examples.abreviator
 (:gen-class))
(println 
(clojure.string/replace
(clojure.string/replace "mississippi land new-york Bank of America chase " #"([\s\w\-_]|^)([a-z0-9-_]+) "
     (fn [[b]]
       (str  (clojure.string/upper-case  (get b 0 ))  (get b 1 ) (get b 2 ) (get b 3 ) (get b 4 ) (get b 5 ) (get b 6 )(get b 7 )
           )))
 #"[ ]" "")           
)
The final result:
MississiLandNew-yorkBankOfAmericaChase 
To run this example online select code and past in Tutorial point coder page:Execute on tutorial point It's aka JSFiddle for but only for Clojure. I likeit . I always use this  Clojure REPTL from Tutorial point

No comments: