function | since v0.0-927 | clojure.string/trim-newline | Edit |
(trim-newline s)
Removes all trailing newline \n
or return \r
characters from string.
Similar to Perl's chomp.
Removes all trailing newline \n or return \r characters from string. Similar to Perl's chomp.
(defn ^string trim-newline
[s]
(loop [index (.-length s)]
(if (zero? index)
""
(let [ch (get s (dec index))]
(if (or (identical? \newline ch)
(identical? \return ch))
(recur (dec index))
(.substring s 0 index))))))