Split a character string based on change of character: Difference between revisions
Split a character string based on change of character (view source)
Revision as of 01:28, 24 October 2017
, 6 years agoAdded XLISP
No edit summary |
(Added XLISP) |
||
Line 1,098:
End Function
</lang>
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
=={{header|XLISP}}==
<lang lisp>(defun delimit (s)
(defun delim (old-list new-list current-char)
(if (null old-list)
new-list
(delim (cdr old-list) (append new-list
(if (not (equal (car old-list) current-char))
`(#\, #\Space ,(car old-list))
(cons (car old-list) nil) ) )
(car old-list) ) ) )
(list->string (delim (string->list s) '() (car (string->list s)))) )
(display (delimit "gHHH5YY++///\\")) ;; NB. The "\" character needs to be escaped</lang>
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
|