Logo

Programming-Idioms

Assign to variable s a string literal consisting in several lines of text, including newlines.
Implementation
Ruby

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Ruby implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
s = """Huey
Dewey
Louie"""
s := `Huey
Dewey
Louie`
$s = "Perl normally allows
strings to contain newlines.";
let s = "line 1
line 2
line 3";
$s = "This string 
is spanning
three lines";
auto s = "One,
Two,
Three
";
var s = '''A
multi-line
string''';
var 
  _s: String;
begin
  _s := 'one' + LineEnding + 'two' + LineEnding + 'three'
end.
s = "Spanning
string
works"
s = unlines [
     "several"
    ,"lines"
    ,"of"
    ,"text"]
S = "Strings
may span
across multiple lines"
"and they can"
"have as many portions"
"as you want"
"all of them quoted".
s = [[
Huey
Dewey
Louie
]]
auto s = `line1
line2
line3`;
string s = @"Huey
Dewey
Louie";
s = """
multiline
heredoc
"""
char *s = "Huey\n"
          "Dewey\n"
          "Louie";
let s = "This is a very long string which needs \n" +
        "to wrap across multiple lines because \n" +
        "otherwise my code is unreadable.";
let s = "This is a very long string which needs \
to wrap across multiple lines because \
otherwise my code is unreadable.";
let s = `This is a very long string which needs 
to wrap across multiple lines because 
otherwise my code is unreadable.`;
$s = <<<EOD
Huey
Dewey
Louie
EOD;
let s = r#"Huey
Dewey
Louie"#;
String s = "This is a very long string which needs \n" +
           "to wrap across multiple lines because \n" +
           "otherwise my code is unreadable.";
val s = """line 1
line 2
line 3"""
(def s "Murs, ville,
Et port,
Asile
De mort,
Mer grise
Où brise
La brise,
Tout dort.")
s = 'Huey \n'..
'Dewey \n'..
'Louie'
#include <string>
std::string s = R"( Earth is a planet.
So is the Jupiter)";
(setf s "a
b
c
d")
val s =
    """
    This is my
    multi-line string.
    """
  s = "Hello &
      &World"
s : String := "Will this compile? " &
     "Oh yes it will";
IDENTIFICATION DIVISION.
PROGRAM-ID. multi-line string.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 s    PIC X(20).
01 str  PIC X(5) VALUE 'COBOL'.
01 str1 PIC X(4) VALUE 'RULE'.
01 str2 PIC X(3) VALUE 'THE'.
01 str3 PIC X(5) VALUE 'WORLD'.
PROCEDURE  DIVISION.       
    STRING str ' ' str1 ' ' str2 ' ' str3 
    DELIMITED BY SIZE INTO s
STOP RUN.
Dim s as String = "
This
Is
Multiline
Text!"
s :: String
s = "We will put a backslash to take a break\
     \and then a backslash to resume"
NSString *s=@"Huey\n"
            @"Dewey\n"
            @"Louie";
def s = """line 1
line 2
line 3"""
def s = """\
	line 1
	line 2
	line 3""".stripIndent()
var s = """A
multi-line
string""";
$s =<<EOSTR;
One of the ways to create multiline text is called
the "here doc" (lifted from various UNIX shells).
A 'here doc' is the <<tag construct.  Perl continues to treat
all the text found as part of the string until there's a line containing
the EOSTR tag at the beginning
EOSTR
$s = q{
There are a good few ways to create multiline
text strings in perl.
};
auto s = r"line1
line2
line3";
String s = """
This is a very long string which needs
to wrap across multiple lines because
otherwise my code is unreadable.
""";
s = ~S"""
This will print multiline
and escape char like \G
"""

(define s "This is my multi-line literal.
Line number two!
  This line starts with two spaces.")
s := 'Will this compile?
Oh yes, it will!'.
val s = """line 1
          |line 2
          |line 3""".stripMargin
s = <<EOS
This is a
multi-line string.
We call it a "heredoc"
EOS
String lineSeparator = System.lineSeparator();
String s = "line1" + lineSeparator + "line2" + lineSeparator;
var 
  s: String;
begin
  s := 'one' + sLineBreak + 'two' + sLineBreak + 'three'
end.
var 
  s: String;
begin
  s := '''
one
two
three
''';
end.