0Pricing
Ruby Academy · Lesson

String Basics and Methods

Common string operations.

What Is a String?

A String is a sequence of characters. In Ruby you create one with single or double quotes.

  • 'hello' is a single-quoted string
  • "hello" is a double-quoted string

Strings are everywhere: names, messages, file contents and more.

greeting = "Hello, Ruby!"
puts greeting

String Length

Use length (or its alias size) to count the characters in a string.

word = "banana"
puts word.length
puts word.size

All lessons in this course

  1. String Basics and Methods
  2. Interpolation and Formatting
  3. Searching and Replacing
  4. Splitting and Joining
← Back to Ruby Academy