Putting quotes in wysiwyg strings
Bill Baxter
wbaxter at gmail.com
Thu Nov 23 13:12:50 PST 2006
Stewart Gordon wrote:
> Bill Baxter wrote:
>
> You missed off
>
> r"foo" \" r"bar";
Thanks. Didn't know that would work.
>> It would be a lot nicer if one could just do:
>>
>> r"foo\"bar";
>
>
> Then how would one put a backslash at the end of a wysiwyg string?
Yeh, using "" for " would be better, as Lionello pointed out. The only
problem is that it changes the meaning of r"""" from an empty string
(currently) to a string
Python has r-strings too, and their rules are really wacky. \" escapes
the quote charater, *but* the backslash still appears in the output.
And r"\" is not possible.
At least D's rule is easy to remember!
> I see now. Do you read the input line by line? If so, you could detect
> whether each line contains '"' or '`', and switch between r"..." and
> `...` at the beginning of the line if necessary. You'll only need such
> messy code as the above for lines that contain both characters.
I think I should just accept that raw strings are not the right tool for
this job. I'll just stick with regular strings as the default and hope
for Perl-ish "here documents" someday.
--bb
More information about the Digitalmars-d
mailing list