ClojureDocs

导航

命名空间

char-array

clojure.core

自 1.1 起可用 (源代码)
  • (char-array size-or-seq)
  • (char-array size init-val-or-seq)
Creates an array of chars
2 Examples
user> (char-array "asdf")
#<char[] [C@167fc18>

user> (seq (char-array "asdf"))
(\a \s \d \f)

user> (seq (char-array 10))
(\^@ \^@ \^@ \^@ \^@ \^@ \^@ \^@ \^@ \^@)
;; `slurp` is polymorphic and supports many types. Sometimes you 
;; need to `slurp` a generic argument that could be already a string
;; (perhaps it was loaded somewhere else). Use `char-array` to convert
;; the string into a format suitable for `slurp`:

(defn fetch [x]
  (slurp (if (string? x) (char-array x) x)))
    
(take 10 (fetch "https://clojure.org"))
;;(\h \t \t \p \: \/ \/ \c \l \o)
(take 10 (fetch "Also loading from a string"))
;; (\A \l \s \o \space \l \o \a \d \i)
See Also

Returns an array with components set to the values in aseq. The array's component type is type if ...

Added by dakrone

Returns an array of Objects containing the contents of coll, which can be any Collection. Maps to...

Added by dakrone

Casts to chars[]

0 Notes
No notes for char-array