Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   multi-line strings with """ (http://www.velocityreviews.com/forums/t822971-multi-line-strings-with.html)

Navindra Umanee 07-15-2005 10:11 AM

multi-line strings with """
 
Hi,

Why is it that multi-line strings that begin with """ close themselves
when a single " is encountered?

irb(main):006:0> """
irb(main):007:0" This is a multi-line string
irb(main):008:0" with a "
=> "\nThis is a multi-line string\nwith a "

I find this to be somewhat annoying. The Python way seems preferable:

>>> """

... In this string I can have isolated "s without worry
... the only way to end the string is with """
'\nIn this string I can have isolated "s without worry\nthe only way to end thestring is with '

Any chance this behavior will change in the next Ruby? :-)

Thanks,
Navin.





YANAGAWA Kazuhisa 07-15-2005 10:44 AM

Re: multi-line strings with """
 
In Message-Id: <20050715061147.A28910@cs.mcgill.ca>
Navindra Umanee <navindra@cs.mcgill.ca> writes:

> Why is it that multi-line strings that begin with """ close themselves
> when a single " is encountered?
>
> irb(main):006:0> """
> irb(main):007:0" This is a multi-line string
> irb(main):008:0" with a "
> => "\nThis is a multi-line string\nwith a "


1. multiple string literals are concatenated.
2. There're no multi-line string specific quotations.

In the above case your string is parsed as "" and "\nThis...." in a
sequence.


> Any chance this behavior will change in the next Ruby? :-)


You can use:

"mere single double-quotation
for multi-line string"

str = <<EOS
or use here document
for multi-line string
EOS


--
kjana@dm4lab.to July 15, 2005
Dreams come true --- excepting yours.





All times are GMT. The time now is 01:39 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.