Solution to replace spaces in string