diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2009-03-17 12:28:15 +0000 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2009-03-17 12:28:15 +0000 |
commit | 7c58716aecf43e7ba7f8157f8b7ee69ab1a1d75e (patch) | |
tree | d3bfb909fd347a07b9c7fdb57d88b195d37e8f42 | |
parent | 33473a7cd3e1c84514888626046c2af1a8afe193 (diff) |
str_utils.clj: added chop and chomp, like Perl
-rw-r--r-- | src/clojure/contrib/str_utils.clj | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/clojure/contrib/str_utils.clj b/src/clojure/contrib/str_utils.clj index d24bbb05..23a9a3b7 100644 --- a/src/clojure/contrib/str_utils.clj +++ b/src/clojure/contrib/str_utils.clj @@ -83,3 +83,15 @@ 'separator'. Like Perl's 'join'." [separator sequence] (apply str (interpose separator sequence))) + + +(defn chop + "Removes the last character of string." + [s] + (subs s 0 (dec (count s)))) + +(defn chomp + "Removes all trailing newline \\n or return \\r characters from + string. Note: String.trim() is similar and faster." + [s] + (re-sub #"[\r\n]+$" "" s)) |