Clojure-snips: Strings in Clojure


Some languages have many ways to create and change Strings. Clojure keeps this simple.

;this is not a string
'NotString' ;Output is NotString'

;this is a String. note the double quotes
"I am a String"

;you cannot add strings to join them so the below won't work
(+ "str1" "str2") ;Exception

;this is the only way to join two strings
(str "hello" "world") ;"helloworld"

;you can have variables also in str function 
;obviously as this is the only way to create strings
(def tmp "tmp")
(str "hello " tmp) ;"hello tmp"
Advertisements

One thought on “Clojure-snips: Strings in Clojure

  1. Pingback: Writing about Clojure | ansh bansal

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s