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)

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

abc789de

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

技术教程推荐

邱岳的产品手记 -〔邱岳〕

Service Mesh实践指南 -〔周晶〕

技术管理实战36讲 -〔刘建国〕

iOS开发高手课 -〔戴铭〕

即时消息技术剖析与实战 -〔袁武林〕

陈天 · Rust 编程第一课 -〔陈天〕

深入C语言和程序运行原理 -〔于航〕

Kubernetes入门实战课 -〔罗剑锋〕

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

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