Idiom #219 Replace multiple spaces with single space
Create the string t from the value of string s with each sequence of spaces replaced by a single space.
Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.
(defun words (str)
(if (equalp str "") nil
(let ((p (position #\Space str )))
(cond ((null p) (list str))
((zerop p ) (words (subseq str 1)))
(T (cons (subseq str 0 p) (words (subseq str (+ 1 p )))))))))
(setf s " aa bbb cc1 ")
(let ((ws (words s )))
(setf t (car ws))
(dolist (w (cdr ws ))
(setf t (concatenate 'string t " " w ))))
(print t)
singleSpace(Text) ->
singleSpace(0, Text).
singleSpace(_, []) -> [];
singleSpace(32, [32 | Rest]) ->
singleSpace(32, Rest);
singleSpace(32, [Ch | Rest]) ->
[Ch] ++ singleSpace(Ch, Rest);
singleSpace(Last, [Ch | Rest]) ->
[Ch] ++ singleSpace(Ch, Rest).
%%singleSpace("this is a text with multiple spaces").