一、创建
函数str:函数 (str) 接受任意数量的参数。如果参数不是字符串则将其转换为字符串,返回创建的新字符串。如果没有参数或为nil,则返回空字符串""
user=>
user=> (str 1)
"1"
user=> (str -2.5)
"-2.5"
user=> (str "a")
"a"
user=> (str "abc" 123)
"abc123"
user=> (str)
""
user=> (str '(1 2 3))
"(1 2 3)"
user=> (str nil)
""
user=> (str null)
java.lang.Exception: Unable to resolve symbol: null in this context (NO_SOURCE_FILE:149)
user=> (str "null")
"null"
user=> (str "abc " 123)
"abc 123"
user=> (str 123 345)
"123345"
其它比较少用的创建函数
print-str、println-str、pr-str、prn-str、with-out-str
user=> (print-str "abc" 234)
"abc 234"
user=> (println-str "abc" 234)
"abc 234\n"
user=> (pr-str "abc" 234)
"\"abc\" 234"
user=> (prn-str "abc" 234)
"\"abc\" 234\n"
user=> (with-out-str "abc" 234)
""
二、string操作count函数:count函数接受字符串参数时,返回字符串的字符数。
user=> (count)
java.lang.IllegalArgumentException: Wrong number of args (0) passed to: core$count (NO_SOURCE_FILE:175)
user=> (count nil)
0
user=> (count "abc123")
6
subs函数:subs函数接受两个或三个参数, 第一个是字符串,第二个是一个整数偏移量,第三个(可选)是另一个整数偏移量。函数返回从第一个偏移量(含),到第二个(不含)偏移量或者结尾(如果没有第二个偏移量)截取的子字符串。
user=> (subs "ithomer" 1)
"thomer"
user=> (subs "ithomer" 1 3)
"th"
user=> (subs "ithomer" 1 (count "ithomer"))
"thomer"
user=> (subs "ithomer" 1 20)
java.lang.StringIndexOutOfBoundsException: String index out of range: 20 (NO_SOURCE_FILE:0)
user=> (subs "ithomer")
java.lang.IllegalArgumentException: Wrong number of args (1) passed to: core$subs (NO_SOURCE_FILE:0)
format函数:format函数用于格式化字符串。使用jdk的java.util.Formatter类完成格式化。
user=> (format "hello %s" "ithomer.net")
"hello ithomer.net"
user=> (format "%5d" 3)
" 3"
user=> (format "%-5d" 3)
"3 "
user=> (format "%05d" 3)
"00003"
检查函数:字符串检查函数 (string?) 接受一个参数,如果是字符串返回true,否则返回false
user=> (string? "abc")
true
user=> (string? "123")
true
user=> (string? 123)
false
user=> (string? nil)
false
字符检查函数(char?)接受一个参数,如果是字符类型返回true,否则返回false
user=> (char? "abc")
false
user=> (char? \a)
true
user=> (char? 'a')
java.lang.Exception: Unmatched delimiter: )
user=> (char? a)
java.lang.Exception: Unable to resolve symbol: a in this context (NO_SOURCE_FILE:222)
user=> (char? 1)
false
user=> (char? \1)
true
user=> (char? nil)
false
分享到:
相关推荐
NULL 博文链接:https://clojure.iteye.com/blog/1741375
在 Clojure 中拆分字符串 该项目演示了在 Clojure 中拆分字符串的各种方法。 选择特定变体时,不要忘记检查输入要求: 一些变体适用于字符集合并支持动态处理和无限集合,一些仅适用于已加载到内存中的字符串。 ...
NULL 博文链接:https://clojure.iteye.com/blog/1742475
Clojure入门教程
clojure-humanize, 在clojure中,生成可以读的字符串 人性化的clojure 基于其他语言的类似库生成可以读字符串的Clojure(script) 库,用于数字。日期命令行 Leiningen( 。通过 Clojars ) 用法numberwordintcommaint
Clojure学习教程.pdf
Clojure入门教程- Clojure – Functional Programming for the JVM中文版
Clojure入门介绍: Clojure - Functional Programming for the JVM
Clojure学习文档,Clojure-Web开发学习,覆盖了Clojure由浅入深的基本学习
Clojure库,用于模糊字符串匹配 它实现以下匹配算法 骰子 莱文施泰因 nilsimsa散列(fuzzy-string.nilsimsa) 用法 将以下内容添加到您的lein项目中: 然后 ( use 'fuzzy-string.core) ( dice " Hair " " Wear ...
本次演讲中,庄晓丹从AVOSCloud这个完全基于Clojure构建的移动云平台出发,分享Avos团队在Clojure上的实践和经验,为国内Clojure的传播贡献一份力量。
latest release 用于将多行字符串文字添加到Clojure的任务例子( def lorem-ipsum ; ;{{ Lorem ipsum dolor sit amet , consectetur adipiscing elit. Nullam eget eleifend metus. Curabitur vitae vestibulum ...
4clojure 学习编程语言 Clojure 的站点这是一个Clojure 答案的存储库。 回答 test runner 进行测试,答案在所在的位置。测试运行器本身也是用 Clojure 编写的。 跑步 它需要 JVM 和 Leiningen 才能运行。运行时,它...
这是Programming Clojure 电子版的 纸质版本在美国亚马逊要到2009年3月才能上架 Paperback: 200 pages Publisher: Pragmatic Bookshelf (March 15, 2009) Language: English ISBN-10: 1934356336 ISBN-13: 978-...
Clear, practical Clojure for the professional programmer Professional Clojure is the experienced developer's guide to functional programming using the Clojure language. Designed specifically to meet ...
cuerdas:Clojure的字符串操作库(脚本)
Clojure is an opinionated language—it doesn’t try to cover all paradigms or provide every checklist bullet-point feature. Instead it provides the features needed to solve all kinds of real-world ...
【1】[Clojure编程乐趣](The Joy of Clojure).pdf ...【4】Clojure Data Analysis Cookbook.pdf 【5】clojure Hand book(中文).pdf 【6】Clojure in Action.pdf 【7】clojure in small pieces.pdf 以上7本书的电子版
Practical Clojure Clojure语言书籍
clojure clojure clojureclojure clojure