Skip to content

Instantly share code, notes, and snippets.

@apg
Created August 16, 2010 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apg/527229 to your computer and use it in GitHub Desktop.
Save apg/527229 to your computer and use it in GitHub Desktop.
Multi-line strings with margin, scala style
user=> (use '[clojure.contrib.str-utils2 :only [split join]])
user=> (defn ml-str
"Scala style multiline string"
[s]
(let [l (split-lines s)]
(join "\n" (map (fn [b]
(let [i (.indexOf b "|")]
(if (> i 0)
(.substring b (inc i))
b))) l))))
#'user/ml-str
user=> (ml-str "Hello World
|the margin will
|be deleted as per
|the request of scala
|users")
"Hello World\nthe margin will\nbe deleted as per\nthe request of scala\nusers"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment