Re: string substitution?
- From: André Thieme <address.good.until.2006.dec.22@xxxxxxxxxxx>
- Date: Thu, 30 Nov 2006 20:02:28 +0100
Pascal Bourguignon schrieb:
André Thieme <address.good.until.2006.dec.22@xxxxxxxxxxx> writes:
georgeryoung@xxxxxxxxx schrieb:[mostly newbie, sbcl, linux]You could do it with cl-ppcre:
I recently tried to do a seemingly simple thing and could not see how.
Given a string, I wanted to substitute a CR-LF for each LF, or if you
prefer, insert a CR before each LF. I'm sure it can be done with some
crufty characater by character loop, but it seems like there should be
an elegant solution.
Either the case of a small string, allowing exploding it into large
data structures, or a constant-memory streaming algorithm would be
interesting.
Any suggestions?
[I ended up doing it in python which was very simple, but my intent is
to learn practical lisp]
(cl-ppcre:regex-replace-all
(string #\Newline)
target-string
(concatenate 'string (string #\Newline) (string #\Return)))
This is incorrect. #\Newline has no relation with CR or LF.
(cl-ppcre:regex-replace-all
(string #\Linefeed)
target-string
(concatenate 'string (string #\Return) (string #\Linefeed)))
At least on sbcl there seems to be a relation:
CL-USER> #\Linefeed
#\Newline
I was following this table:
http://www.robelle.com/smugbook/ascii.htmlb
And after checking that (code-char 10) -> #\Newline
I put it in the code.
André
--
.
- Follow-Ups:
- Re: string substitution?
- From: Pascal Bourguignon
- Re: string substitution?
- References:
- string substitution?
- From: georgeryoung
- Re: string substitution?
- From: André Thieme
- Re: string substitution?
- From: Pascal Bourguignon
- string substitution?
- Prev by Date: Re: SBCL just turned 1.0!
- Next by Date: Re: SBCL just turned 1.0!
- Previous by thread: Re: string substitution?
- Next by thread: Re: string substitution?
- Index(es):
Relevant Pages
|