Clojure 中的 replace函数

首页 / Clojure入门教程 / Clojure 中的 replace函数

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)

上面的程序产生以下输出。

链接:https://www.learnfk.comhttps://www.learnfk.com/clojure/clojure-regular-expressions-replace.html

来源:LearnFk无涯教程网

abc789de

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入浅出区块链 -〔陈浩〕

实用密码学 -〔范学雷〕

A/B测试从0到1 -〔张博伟〕

玩转Vue 3全家桶 -〔大圣〕

React Native 新架构实战课 -〔蒋宏伟〕

快手 · 移动端音视频开发实战 -〔展晓凯〕

商业思维案例笔记 -〔曹雄峰〕

技术领导力实战笔记 2022 -〔TGO 鲲鹏会〕

云原生架构与GitOps实战 -〔王炜〕

好记忆不如烂笔头。留下您的足迹吧 :)