1.3.0 permalink Arrow_down_16x16

trim-newline

clojure.string

  • (trim-newline s)
Removes all trailing newline \n or return \r characters from
string. Similar to Perl's chomp.

1 Example top

  • user=> (clojure.string/trim-newline "test\n\r")
    "test"
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/string.clj:212 top

(defn ^String trim-newline
  "Removes all trailing newline \\n or return \\r characters from
  string.  Similar to Perl's chomp."
  {:added "1.2"}
  [^CharSequence s]
  (loop [index (.length s)]
    (if (zero? index)
      ""
      (let [ch (.charAt s (dec index))]
        (if (or (= ch \newline) (= ch \return))
          (recur (dec index))
          (.. s (subSequence 0 index) toString))))))
Vars in clojure.string/trim-newline:
Used in 0 other vars

Comments top

No comments for trim-newline. Log in to add a comment.