What are delimited strings good for?

Jonathan M Davis jmdavisProg at gmx.com
Sun Apr 10 12:00:45 PDT 2011


> On 10/04/2011 17:51, Jonathan M Davis wrote:
> >> Ref http://digitalmars.com/d/2.0/lex.html
> >> 
> >> What are some possible use cases for delimited strings?
> >> What is solved by having this in the language?
> > 
> > It's probably so that you can still use characters that require escaping
> > in the string without having to escape " everywhere. WYSIWYGS don't
> > allow for escaping characters, which can be annoying periodically.
> > Still, delimited strings do seem a bit funny to me, and I don't think
> > that I've ever used them. Presumably, they solved some problem fairly
> > nicely, but the only thing that I can think of is that they still allow
> > for characters that require escaping but don't force you to escape ",
> > which could be very useful in strings with lots of "s and other
> > characters that need escaping.
> > 
> > - Jonathan M Davis
> 
> DelimitedString:
> 	q" Delimiter WysiwygCharacters MatchingDelimiter "
> 
> Therefore you can choose you delimiter, which as you say might be " Also
> it looks like you can't use any escapes, because it says
> WysiwygCharacters above.
> 
> and further down:
> 
> Wysiwyg Strings
> 
> Wysiwyg quoted strings are enclosed by r" and ". All characters between
> the r" and " are part of the string except for EndOfLine which is
> regarded as a single \n character. There are no escape sequences inside
> r" ":
> 
> I take that to mean that you can't use escapes in DelimitedStrings, either.
> 
> This would be quite useful for regex, for example.

I didn't read carefully enough then. I thought that delimited strings allowed 
for escaped characters. If they don't, then I really don't understand why they 
exist. WYSIWYG strings already do that for you. All you have to do is use 
backticks instead of double quotes. Maybe backticks aren't on all types of 
keyboards? If so, that might explain the addition, but other than that, the 
only thing that I can think of is if you want a WYSIWYG string with lots of 
backticks in it.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list