You're viewing version 1.2.0 of str. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (str)
  • (str x)
  • (str x & ys)
With no args, returns the empty string. With one arg x, returns
x.toString(). (str nil) returns the empty string. With more than
one arg, returns the concatenation of the str values of the args.

2 Examples top

  • user=> "some string"
    "some string"
    user=> (str)
    user=> (str nil)
    user=> (str 1)
    user=> (str 1 2 3)
    user=> (str 1 'symbol :keyword)
    ;; A very common usage of str is to apply it to an existing collection:
    user=> (apply str [1 2 3])
    ;; compare it with:
    user=> (str [1 2 3])
    "[1 2 3]"
  • ;; Destructuring with a string, getting just a few characters from it
    user=> (let [[first-char second-char] "abcde"] 
             (prn 'first= first-char) 
             (prn 'second= second-char))
    first= \a
    second= \b
    ;; More destructuring with a string
    user=> (let [[first-char second-char & rest-of-chars] "abcde"] 
             (prn 'first= first-char) 
             (prn 'second= second-char) 
             (prn 'rest= rest-of-chars))
    first= \a
    second= \b
    rest= (\c \d \e)
    ;; Destructuring, getting the first character of a string
    ;; and then a reference to the entire string
    user=> (let [[first-char :as all-the-string] "abcde"] 
             (prn 'first= first-char) 
             (prn 'all= all-the-string))
    first= \a
    all= "abcde"
Log in to add / edit an example.

See Also top

  • 0

    Prints the object(s) to the output stream that is the current value

  • 0

    Same as pr followed by (newline). Observes *flush-on-newline*

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:449 top

(defn str
  "With no args, returns the empty string. With one arg x, returns
  x.toString().  (str nil) returns the empty string. With more than
  one arg, returns the concatenation of the str values of the args."
  {:tag String
   :added "1.0"}
  ([] "")
  ([^Object x]
   (if (nil? x) "" (. x (toString))))
  ([x & ys]
     ((fn [^StringBuilder sb more]
          (if more
            (recur (. sb  (append (str (first more)))) (next more))
            (str sb)))
      (new StringBuilder ^String (str x)) ys)))
Vars in clojure.core/str: defn first fn next nil?
Used in 219 other vars (expand)
the-ns time gensym spit gen-interface print-namespace-doc extend munge import print-doc with-out-str assert slurp -cache-protocol-fn proxy-name namespace-munge refer proxy clojure-version print-special-doc print-simple old-table-model browse-url as-relative-path delete-file source source-fn join replace capitalize replace-first testing-contexts-str testing-vars-str message-el finish-element start-element test-name print-tap-plan emit-element make-map join slurp* write-lines deferror raise* source generate-toggle-namespace-script get-source generate-all-namespaces-action-script find-javadoc-url qsym slurp* write-lines delete-file as-str delete-file browse-url as-str emit log spy enabled? unexpected-args print-repl-info print-sql-exception create-table re-sub str-join re-gsub repeat map-str join capitalize grep repeat map-str replace-first-by capitalize grep << do-template testing-contexts-str testing-vars-str apply-template tracer trace-indent trace-fn-call text defservice header area-chart* time-series-plot box-plot add-box-plot stacked-area-chart* save stacked-bar-chart bar-chart heat-map view xy-plot scatter-plot dynamic-scatter-plot line-chart function-plot add-categories* box-plot* histogram sliders stacked-bar-chart* bar-chart* add-function stacked-area-chart area-chart dynamic-xy-plot add-histogram line-chart* query-to-pred lee-distance n-grams hamming-distance safe-ant-name make-path clean deps ns->path defproject help-summary-for help-for get-default-jar-name make-manifest get-jar-filename make-pom make-pom-properties new make-git-scm read-git-ref relative-path get-default-uberjar-name test-namespaces colorize str->ansi-color-str defconfig resolve! defn! unexpected-args string-of data-name-for-generator-coll char-generator test-namespaces result-string indent indents default-error-message default-fail-message make-test-name test-function-name debug-repl java-props->sh-args test-ns->source-ns test-namespace reload-exception-message source-ns->test-ns add-class text html-snippet sniptest* send-repl-results-to-emacs cause-restart-for swank-toggle-trace unmunge char-position locals-for-emacs exception-stacktrace find-definitions-for-emacs list-all-package-names set-package largest-common-prefix debugger-condition-for-emacs with-package-tracking potential-dot potential-completions swank-require variable-desc-for-echo-area unacronym delimited-compound-prefix-match? label-value-line inspectee-title describe-inspectee print-part-to-string read-chars start-server-socket! announce-port-to-file slime-secret-path clj-file? init file-name-to-swank-package-sym *swank-compile-path* swank-version encode-message fake ssh-sftp-cmd ssh-shell memfn-varargs capitalize partial-namespace-matcher new-sandbox new-sandbox-compiler dot-maker namespace-matcher expand-and-quote <3 kw-to-setter str-remove string-ref-content str-insert report-problem unexpected-args defcontract

Comments top

No comments for str. Log in to add a comment.