0

I have an issue with formatting an IO String, and don't know how i could do that.

For example:

tryA (arrIO (\s -> hPutDocument (\h -> hPutStrLn h 
=<< readProcess "grep" ["-n",s,"camera2.owl"] "")))

As it was mentioned on my post asked today Here, i figured out that my String s has a lot of things which i don't need it.

For example, normally i have that String on s:

<owl:Class rdf:about="http://www.xfront.com/owl/ontologies/camera/#SLR">   </owl:Class>

And what i want , it is to delete the spaces available after > and remove the close tag which is </owl:Class>

How could i do that on haskell ? I must do the transformation before it is sent to my grep function.

P.S. : Maybe i could use some regular expressions with a type <.> and after that he removes it. (Doing the lesser match of course,or it will give me the full match)

Community
  • 1
  • 1
Damiii
  • 1,363
  • 4
  • 25
  • 46
  • 2
    Could you please reformat your code snippet? The extensive nesting is rather hard to grasp within a single line. Also, I wanted to take a stab at it myself, but then I noticed the parentheses don't match. – radomaj Jun 15 '14 at 17:51
  • 1
    Sorry about the parentheses, didn't saw earlier. Thanks for the help ! :) – Damiii Jun 16 '14 at 11:49

1 Answers1

0

As long as there are always spaces before the closing tag and the tag itself doesn't have them, the most minimal way to remove it from a String to me would be:

import Data.List

removeClosingTag = unwords . init . words

From a GHCi session I just ran:

λ> 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\">"

EDIT: Warning: init is not total and will give you a runtime error on an empty list [].

radomaj
  • 841
  • 8
  • 18