且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用替换映射替换字符串上的多个单词

更新时间:2023-02-19 23:27:48

一个选项:在 Map 上使用 foldLeftstr 作为初始参数:

One option: use foldLeft on the Map with str as the initial parameter:

replacements.foldLeft(str)((a, b) => a.replaceAllLiterally(b._1, b._2))
// res8: String = This d is very x and I would love to mxc