haskelldude
haskelldude

Reputation: 1

How can I remove a certain character from a string in Haskell?

I want to make a function that removes a given character from a string. The prototype is: removeChar :: Char -> String -> String I tried to do something like this:

removeChar a x =  foldr (++) [] (map (\x -> filter f x) x)
           where 
           f x = elem a x

Upvotes: 0

Views: 169

Answers (1)

vijaicv
vijaicv

Reputation: 555

this should be enough, String is nothing but a [Char] so just filter it for that char

removeChar::Char->String->String
removeChar a = filter (/=a)

Upvotes: 1

Related Questions