Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

string
ruby
communitycreator

How to remove the first character of a string in Ruby using chr

okwudili onyejiaku

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 strings
str1 = "Welcome"
str2 = "to"
str3 = "Edpresso"

# remove first characters
a = str1.chr
b = str2.chr
c = str3.chr

# print returned values
puts a 
puts b
puts c
Remove first characters of a string with the chr method in Ruby

As we can see above, the first characters of the strings were removed and printed out on the console.

RELATED TAGS

string
ruby
communitycreator
RELATED COURSES

View all Courses

Keep Exploring