← Back to Ruby Course | Chapter 3: Strings | Lesson 2 of 7

Multiline Strings

In this page:

  1. Multiline Strings

Multiline Strings

A Ruby string literal can span multiple lines directly inside quotes, preserving the line breaks as part of the string's content. This is simpler than using explicit \n characters for short multi-line text. For longer blocks of text, a heredoc (covered next) is usually more readable.

Note: Line breaks typed directly inside a quoted string become literal newline characters in the resulting string.

Example: Multiline Strings

markup
message = "Line one
Line two
Line three"

puts message
puts message.lines.count
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.