literal backslash



Hi,

How are you supposed to create strings with literal backslashes in
them?

I need a function that takes some string and returns another with any
single quotes backslashed.

(defun js-escape (str)
(with-output-to-string (s)
(loop for char across str do
(case char
(#\' (prin1 "\'" s))
(otherwise (princ char s))))))

I tried various combinations of prin1, princ and print with single and
double backslashes in the "replacement" string above but nothing
seemed to work.

Cheers,
Andy
.



Relevant Pages

  • Re: 2 questions: directory search and user creator
    ... You're comparing a character to a string address. ... character codes of space and newline use single quotes, ... # /* this part needs to add th char ch to a string pass*/ ...
    (comp.unix.programmer)
  • Re: quotes from form input + MySQL insert query
    ... string mysql_escape_string ... > same way, but a textarea string full of single quotes is handled fine, while ... I've checked the POSTed data by echoing ... > backslashes, in case the single ones generated by magic_quotes weren't ...
    (alt.php)
  • Re: literal backslash
    ... I need a function that takes some string and returns another with any ... (loop for char across str do ... (otherwise (princ char s)))))) ... double backslashes in the "replacement" string above but nothing ...
    (comp.lang.lisp)
  • Re: how to double single quote (beginner blockage)
    ... > String doesn't have a each_with_index method. ... > yield char, counter ... into four single quotes but the solution he envisions would detect them as ...
    (comp.lang.ruby)
  • Re: literal backslash
    ... Using doubled backslashes: ... (loop for char across str do ... double backslashes in the "replacement" string above but nothing ... contain single quotes, but it saves consing up a new string and the ...
    (comp.lang.lisp)