How to remove the first character of a string in Ruby using chr
Overview
The chr method removes the first character of a string in Ruby. It removes the one-character string at the beginning of a string and returns this character.
Syntax
str.chr
Parameters
str: This is the string that calls the chr method.
Return value
The string’s first character is returned, which calls the chr method.
# create some stringsstr1 = "Welcome"str2 = "to"str3 = "Edpresso"# remove first charactersa = str1.chrb = str2.chrc = str3.chr# print returned valuesputs aputs bputs c
As we can see above, the first characters of the strings were removed and printed out on the console.