In Ruby, we can permanently delete characters from a string by using the
string.delete method. It returns a new string with the specified characters removed.
str: this is the string from which we want to delete some characters permanently.
other_string: this is a mandatory string that contains the specified characters we want to delete from
The value returned is a string that does not contain the characters specified to remove. If
str is not modified by this method, nothing or nil is returned.
# create some strings str1 = "Edpresso" str2 = "is" str3 = "awesome" # delete some characters str1.delete! "es" str2.delete! "s" str3.delete! "ew" # print modified strings puts str1 puts str2 puts str3
deletemethod and pass strings that contain the characters we want to delete.
View all Courses