I think you are looking for the JavaScript method string.replace ().
If you want to remove all spaces, use this:
"abc def. fds sdff.".replace(/\s/g, ''); Returns: "abcdef.fdssdff."
If you want to remove only two spaces, use:
"abc def. fds sdff.".replace(/\s\s/g, ' '); Returns: "abc def. fds sdff."
If you want to leave a space after a period, use:
"abc def. fds sdff.".replace(/[^.]\s/g, '') Returns: "abcdef. fdssdff."
Ehryk
source share