Skip to content
Justice Tech School

String Methods

upcase, downcase, capitalize, strip, split, gsub, include?, start_with?, reverse and center cover everyday needs.

Example
s = "  hello world  "
t = s.strip
puts t.upcase, t.capitalize, t.include?("wor"), t.reverse
puts t.gsub("o", "0"), t.split.inspect, "x".center(5, "*")

Result

HELLO WORLD
Hello world
true
dlrow olleh
hell0 w0rld
["hello", "world"]
**x**

Exercise

Replace text.

s.("a", "b")

Quiz Test

What does strip remove?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.