Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 删除xml行的空格和闭包标记_Haskell - Fatal编程技术网

Haskell 删除xml行的空格和闭包标记

Haskell 删除xml行的空格和闭包标记,haskell,Haskell,我在格式化IO字符串时遇到问题,不知道如何才能做到这一点 例如: tryA (arrIO (\s -> hPutDocument (\h -> hPutStrLn h =<< readProcess "grep" ["-n",s,"camera2.owl"] ""))) 我想要的是,删除之后可用的空格,并删除关闭标记 我怎么能在haskell身上这么做? 我必须在将其发送到grep函数之前进行转换 附言: 也许我可以使用一些带有类型的正则表达式,然后他将其删除。(当然

我在格式化IO字符串时遇到问题,不知道如何才能做到这一点

例如:

tryA (arrIO (\s -> hPutDocument (\h -> hPutStrLn h 
=<< readProcess "grep" ["-n",s,"camera2.owl"] "")))
我想要的是,删除
之后可用的空格,并删除关闭标记

我怎么能在haskell身上这么做? 我必须在将其发送到grep函数之前进行转换

附言:
也许我可以使用一些带有
类型的正则表达式,然后他将其删除。(当然,进行较小的匹配,否则将得到完整匹配)

只要结束标记之前始终有空格,并且标记本身没有空格,那么从字符串中删除它的最简单方法是:

import Data.List

removeClosingTag = unwords . init . words
我刚刚在GHCi会议上运行了:

λ> let myString = "<owl:Class rdf:about=\"http://www.xfront.com/owl/ontologies/camera/#SLR\">   </owl:Class>"
λ> (unwords . init . words) myString
"<owl:Class rdf:about=\"http://www.xfront.com/owl/ontologies/camera/#SLR\">"
λ>让myString=“”
λ> (unwords.init.words)myString
""

编辑:警告:init不是total,将在空列表[]上显示运行时错误。

请重新格式化代码段好吗?在一条线内很难掌握广泛的嵌套。另外,我想亲自尝试一下,但后来我注意到括号不匹配。很抱歉括号,我之前没有看到。谢谢你的帮助!:)
λ> let myString = "<owl:Class rdf:about=\"http://www.xfront.com/owl/ontologies/camera/#SLR\">   </owl:Class>"
λ> (unwords . init . words) myString
"<owl:Class rdf:about=\"http://www.xfront.com/owl/ontologies/camera/#SLR\">"