haskell – 为什么Data.Text.Lazy.replace和Data.Text.Lazy.appe
发布时间:2020-12-14 18:30:45 所属栏目:资源 来源:网络整理
导读:在下面的代码中,有三种不同的方式(str1,str2和str3)使用Data.Text.Lazy.replace替换字符串.他们应该提供相同的输出. import Data.Text.Lazy as DTLstr1 :: Stringstr1 = DTL.unpack $DTL.replace key value text where key = DTL.pack "name" value = DTL.pa
在下面的代码中,有三种不同的方式(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 where key = DTL.pack $"<<" ++ "name" ++ ">>" value = DTL.pack "Joyce" text = DTL.pack "Hello,<<name>>." main :: IO () main = do putStrLn str1 putStrLn str2 putStrLn str3 然而,运行该程序的结果是: Hello,Joyce. Hello,<<name>>. Hello,Joyce. 为什么str2无法正常工作?代码有什么问题吗? 解决方法
伙计们,感谢错误报告.我会调查一下,然后按照我的发现跟进.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |