String Methods
In this page:
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
text = " Hello, Ruby! "
puts text.strip
puts text.strip.upcase
puts text.strip.length
puts text.strip.reverse
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: