I am writing a function that can take a string that contains spaces to produce the output such as this: "http://cs.edu/my space/.html" == "http://cs.edu/my%20space/.html"
I successfully have it using concat, but I want it with recursion now this is what I came up with until now:
changer [] = []
changer (x:xs) = go x xs
where go ' ' [] = "%20"
go y [] = [y]
go ' ' (x:xs) = '%':'2':'0': go x xs
go y (x:xs) = y: go x xs
I can not figured out how to use guard efficiently here, or something else appropriate that working fine. Obviously, I am not using recursion effectively as above code, I need a help to reform it using recursion and with the appropriate type signature for my function changer.
The following is my other code i tried to recursive the main function changer instead of using go the helper:
sanitize [] = []
sanitize (x:xs)
|sanitize x xs = sanitize xs
|sanitize y [] = [y]
|sanitize ' ' (x:xs) = '%':'2':'0': go x xs
|sanitize y (x:xs) = y: go x xs
where go ' ' [] = "%20"
It is complaining about y " Not in scope: `y'" Thanks a lot!
sanitizein the same way you did withgooriginally (you didn't need any|s).