Another one
(defun disspacify (str / regexp)
(if
(setq regexp (vlax-get-or-create-object "vbscript.regexp"))
(progn
(vlax-put-property regexp 'global actrue)
(vlax-put-property regexp 'pattern " +")
(vlax-invoke regexp 'replace (vl-string-trim " " str) " ")
)
)
)
_$ (disspacify " This is a normal string. ")
"This is a normal string."
_$
[Edit]: Why not full regular expression... Plus, the dot or comma inside the string needs special treatment:
(defun disspacify (str / regexp)
(if
(setq regexp (vlax-get-or-create-object "vbscript.regexp"))
(progn
(vlax-put-property regexp 'global actrue)
(foreach x '(
(" +[.]|[.]" . ". ");"end ." to "end. "
(" +[,]|[,]" . ", ");"mid ," to "mid, "
(" +" . " ");replace multiple spaces
("^ +| +$" . "");remove start and end space(s)
)
(vlax-put-property regexp 'pattern (car x))
(setq str (vlax-invoke regexp 'replace str (cdr x)))
)
)
)
)
_$ (disspacify " This is a double sentence ,the other one is not .This is a normal string . ")
"This is a double sentence, the other one is not. This is a normal string."
_$