clojure.string
(source)Clojure String utilities
It is poor form to (:use clojure.string). Instead, use require
with :as to specify a prefix, e.g.
(ns your.namespace.here
(:require [clojure.string :as str]))
Design notes for clojure.string:
1. Strings are objects (as opposed to sequences). As such, the
string being manipulated is the first argument to a function;
passing nil will result in a NullPointerException unless
documented otherwise. If you want sequence-y behavior instead,
use a sequence.
2. Functions are generally not lazy, and call straight to host
methods where those are available and efficient.
3. Functions take advantage of String implementation details to
write high-performing loop/recurs instead of using higher-order
functions. (This is not idiomatic in general-purpose application
code.)
4. When a function is documented to accept a string argument, it
will take any implementation of the correct *interface* on the
host platform. In Java, this is CharSequence, which is more
general than String. In ordinary usage you will almost always
pass concrete strings. If you are doing something unusual,
e.g. passing a mutable implementation of CharSequence, then
thread-safety is your responsibility.
For more info about this library see:
https://clojuredocs.org/clojure.corePublic Variable | Short Description |
---|---|
blank? (clj) | True if s is nil, empty, or contains only whitespace. |
capitalize (clj) | Converts first character of the string to upper-case, all other characters to lower-case. |
ends-with? (clj) | True if s ends with substr. |
escape (clj) | Return a new string, using cmap to escape each character ch from s as follows: If (cmap ch) is nil, append ch to the new string. |
includes? (clj) | True if s includes substr. |
index-of (clj) | Return index of value (string or char) in s, optionally searching forward from from-index. |
join (clj) | Returns a string of all elements in coll, as returned by (seq coll), separated by an optional separator. |
last-index-of (clj) | Return last index of value (string or char) in s, optionally searching backward from from-index. |
lower-case (clj) | Converts string to all lower-case. |
re-quote-replacement (clj) | Given a replacement string that you wish to be a literal replacement for a pattern match in replace or replace-first, do the necessary escaping of special characters in the replacement. |
replace (clj) | Replaces all instance of match with replacement in s. |
replace-first (clj) | Replaces the first instance of match with replacement in s. |
reverse (clj) | Returns s with its characters reversed. |
split (clj) | Splits string on a regular expression. |
split-lines (clj) | Splits s on \n or \r\n. |
starts-with? (clj) | True if s starts with substr. |
trim (clj) | Removes whitespace from both ends of string. |
trim-newline (clj) | Removes all trailing newline \n or return \r characters from string. |
triml (clj) | Removes whitespace from the left side of string. |
trimr (clj) | Removes whitespace from the right side of string. |
upper-case (clj) | Converts string to all upper-case. |