在下面的代码三种不同的方法(str1,str2,和str3使用替换字符串)Data.Text.Lazy.replace.他们应该提供相同的输出.
import Data.Text.Lazy as DTL
str1 :: String
str1 = DTL.unpack $ DTL.replace key value text
where key = DTL.pack "<<name>>"
value = DTL.pack "Joyce"
text = DTL.pack "Hello, <<name>>."
str2 :: String
str2 = DTL.unpack $ DTL.replace key value text
where key = DTL.pack "<<" `DTL.append` DTL.pack "name"
`DTL.append` DTL.pack ">>"
value = DTL.pack "Joyce"
text = DTL.pack "Hello, <<name>>."
str3 :: String
str3 = DTL.unpack $ DTL.replace key value text …Run Code Online (Sandbox Code Playgroud) haskell ×1