Ruby | String delete_prefix! Method
delete_prefix! is a String class method in Ruby which is used to return a a copy of the given string with leading prefix deleted or nil if no change was made.
Syntax: str.delete_prefix
Parameters: Here, str is the given string.
Returns: A copy of the given string with leading prefix deleted or nil if no change was made.
Example 1:
# Ruby program to demonstrate # the delete_prefix! method # Taking a string and # using the methodputs "Ruby".delete_prefix!("Ru")puts "Class".delete_prefix!("Cl") |
Output:
by ass
Example 2:
# Ruby program to demonstrate # the delete_prefix! method # Taking a string and # using the methodputs "Sample".delete_prefix!("am")puts "Input".delete_prefix!("In") |
Output:
put
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.


