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

String Methods

In this page:

  1. String Methods

String Methods

Ruby strings come with a large set of built-in methods for transformation and inspection, like .upcase, .downcase, .reverse, .length, and .strip. Most string methods return a new string rather than modifying the original, following Ruby's general preference for non-mutating operations. Methods ending in ! (like .upcase!) mutate the string in place instead.

Note: A method ending in ! (like upcase!) usually mutates the receiver in place -- the non-! version returns a new object instead.

Example: String Methods

markup
text = "  Hello, Ruby!  "

puts text.strip
puts text.strip.upcase
puts text.strip.length
puts text.strip.reverse
🔒

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.