【发布时间】:2018-06-18 10:55:37
【问题描述】:
我有一个带有一些标记的字符串,如下所示:
"There are two things to be replaced. {Thing1} and {Thing2}"
我想用不同的值替换每个标记,所以最终结果如下所示:
"There are two things to be replaced. Don and Jon"
我创建了一个像这样链接 String.Replace 的函数
let doReplacement (message:string) (thing1:string) (thing2:string) =
message.Replace("{Thing1}", thing1).Replace("{Thing2}", thing2)
问题是当我链接 .Replace 时,值必须保持在同一行。这样做不起作用:
let doReplacement (message:string) (thing1:string) (thing2:string) =
message
.Replace("{Thing1}", thing1)
.Replace("{Thing2}", thing2)
为了让我做一个多线链,我在想这样的事情:
message
|> replaceString "{Thing1}" thing1
|> replaceString "{Thing2}" thing2
具有这样的支持功能:
let replaceString (message:string) (oldValue:string) (newValue:string) =
message.Replace(oldValue, newValue)
但是,这不起作用。有没有其他方法可以解决这个问题?
【问题讨论】:
标签: f#