in reply to replace and remove spaces

And?

What do you expect from us? We can't see the code you've tried already and you haven't told us where you are having trouble so: what do you expect from us?

You haven't even told us what the criteria are for determining when to replace spaces and when to remove them. Maybe you need a better problem description and to show that you've actually tried to solve the problem yourself?

True laziness is hard work