To remove a specific character from a string in Ruby, there are various methods available. Here are a few examples:
delete
method:main.rb77 chars4 lines
gsub
method:main.rb90 chars4 lines
tr
method:main.rb88 chars4 lines
Note that these methods will remove all occurrences of the specified character. If you only want to remove the first occurrence, you can use the sub
method instead of gsub
or add an optional parameter to delete
or tr
to limit the number of replacements:
main.rb326 chars12 lines
gistlibby LogSnag