You can use JavaScript in Captivate, so it sounds like you're on the right track. I'd probably pass the Captivate variable associated with the text entry box to a JavaScript variable, use replace (does it need to loop to get all the spaces? I'm new to this, so I'd have to experiment), and then pass the result back to either the original variable or a new Captivate variable, which you display in a caption on the next slide.
Here are a few links to get you started using JavaScript within Captivate, if that's the part you're stuck on:
http://captivatedev.com/series/captivate-javascript-series/
http://captivatedev.com/2012/07/01/adobe-captivate-6-the-javascript-ap i/
Make sure to use the right syntax/API when referring to Captivate variables, depending on whether your output is HTML5 or a SWF. There are also differences between Captivate 5.5 and Captivate 6 (see the second link). If you are using Captivate 6, SCORM, and Internet Explorer, check out this link and do some tests to make sure JavaScript works in your courses before you do lots of hard work: http://www.cpguru.com/warning-adobe-captivate-6-and-javascript-bug/