I am working with strings that have different number of spaces between the non-whitespace characters. The problem is that this strings form a category, and they have to be equal. I would like to format them to have exactly the same number of spaces between the non-whitespace characters, f.e. 1
, but this could be generalised to insert more spaces if possible. And there should be no spaces at the beginning and end.
Examples with n=1
:
'a b b' => 'a b c'
' a b c ' => 'a b c'