[swift-evolution] Long, multiline strings

Carlos Rodríguez Domínguez khain2007 at gmail.com
Mon Dec 21 12:02:18 CST 2015

In many cases, it is necessary to include in the code very long strings, spanning multiple lines. An example could be to include a piece of JavaScript code, XML, HTML, JSON, etc. Currently, we include those strings between ““, which makes it impossible for the IDE to understand that we are “including” external code, potentially providing syntax highlighting, autocompletion, etc. Moreover, at the end of each line it is necessary to include a “\n” character and each “ character needs to be escaped.

My idea is to include a new operator to generate multiline strings, similar to PHP, in which you can write something like this:

$text = <<<EOT 
  Place your text between the EOT. It's
  the delimiter that ends the text
  of your multiline string.
This new feature could be highly beneficial, since it is increasingly common to mix multiple codes inside our own code. Furthermore, it could open the possibility to use Swift in Web environments in a friendlier manner (e.g. to generate HTML code faster, with syntax coloring, etc.). 

- Carlos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151221/bfaed38a/attachment.html>

More information about the swift-evolution mailing list