Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Whether it's written in Ruby or another language, almost all software needs to work with text. Programming languages represent text in the form of strings. A string is just a series of text characters. All languages let you work with strings, but Ruby makes it especially convenient.
- A string is a series of text characters
- A string can be surrounded by single or double-quotes.
'A string'
"Also a string"
- Almost all characters within string surrounded by single quotes appear as they are typed:
puts 'I #{represent} "characters" verbatim.'
- Some punctuation marks within double-quoted strings are interpreted specially:
puts "I make some substitutions: #{2 + 4}"
[MUSIC]
0:00
Whether it's written in Ruby or
another language,
0:04
almost all software
needs to work with text.
0:07
Programming languages represent
text in the form of strings.
0:10
A string is just a series
of text characters.
0:14
All languages let you work with strings,
but Ruby makes it especially easy.
0:18
Ruby provides over 170 methods
you can call on strings,
0:23
which do things like splitting them into
pieces, capitalizing them, and more.
0:27
In this course though, we'll focus
on just a few simple operations,
0:31
including joining strings together and
adding data into the middle of the string.
0:35
A string is just a series
of text characters.
0:41
A handy way to visualize is to picture
a banner that you might hang at a party
0:44
that is stringing together
individual characters.
0:48
They can be surrounded by single or
double quotes.
0:51
Almost all characters within a string
that's surrounded by single quotes
0:54
appear exactly as they're typed.
0:57
So you can see this single
quoted string here,
0:59
which contains a bunch
of special characters.
1:02
And you can see that those special
characters appear exactly as
1:04
is down on the output.
1:07
Some punctuation marks within
double-quoted strings are interpreted
1:09
specially though.
1:13
This double-quoted string has
a special marker within it,
1:14
that includes the expression 2 + 4, and
1:18
you can see that 2 + 4 has been replaced
by the result 6, down here in the output.
1:20
We'll talk more about this in
1:26
You need to sign up for Treehouse in order to download course files.
Sign up