Anonymous user
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 21:11, 29 May 2017
, 7 years ago→{{header|Common Lisp}}
m (→{{header|Fortran}}: Crossreference.) |
|||
Line 247:
=={{header|Common Lisp}}==
<lang lisp>(defun split (string)
(loop :for prev := nil :then c
:for c :across string
:do (format t "~:[~;, ~]~c" (and prev (char/= c prev)) c)))
(split "gHHH5YY++///\\")
</lang>
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
Doing more work that what's being ask, the following solution builds a list of strings then output it:
<lang lisp>(defun split (string)
(flet ((make-buffer ()
|