Created
August 16, 2010 16:28
-
-
Save apg/527229 to your computer and use it in GitHub Desktop.
Multi-line strings with margin, scala style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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