我需要针对外部文件传递一个字符串,该文件包含每次出现时要执行的替换列表。
替换文件将如下所示(我愿意接受有关结构的建议,它可以是 csv、yaml 等...)
"ipsum" "foobar"
"elit" ""
"sit amet" "2312"
我的 ruby 代码应该这样实现:
mystring = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quis elit augue. Nulla tempus magna nec ligula dapibus malesuada. Fusce at orci augue, sit amet suscipit sem. Suspendisse potenti."
newstring = mystring.somemagichappenshere
并且 newstring 值应该是"Lorem foobar dolor 2312, consectetur adipiscing . Aliquam quis augue. Nulla tempus magna nec ligula dapibus malesuada. Fusce at orci augue, 2312 suscipit sem. Suspendisse potenti."
我应该如何实施?