Please see attached.
It works up to 15 spaces, Infopath limitation. Hopefully that is enough for what you need. You could get it to do more if using code, but a rules based version works for most cases.
I got it to work using 3 fields. 2 of them can be hidden.
Field 1 is the input field.
Field 2 is an eval field that checks if field 3 has any " " in the field
Field 3 is the finished field
Field 4 is a counter field
If you look at each field you can see the rules applied to them.
Field 1 has 1 rules, it copies itself into Field 3 and sets Field 4 to 0.
Field 2 has no rules.
Field 3 has 3 rules, one that evals to Field 2, one that adds 1 to field 4 and concats back on itself, and one that finishes the concat when there are no more " "
Field 4 has no rules
There may be a better way to do this, but this way works.