replace
replace函数用于用新的字符串值更换字符串中的子字符串
replace - 语法
(replace str pat replacestr)
参数 - “ pat”是正则表达式模式, “ str”是需要根据模式在其中找到文本的字符串, “replacestr”是需要根据模式在原始字符串中替换的字符串。
replace - 示例
(ns clojure.examples.example (:gen-class));; This program displays Hello Learnfk (defn Example [] (def pat (re-pattern "\d+")) (def newstr (clojure.string/replace"abc123de" pat "789")) (println newstr)) (Example)
上面的程序产生以下输出。
abc789de