Paladini
Paladini

Reputation: 4572

Delete the first "#" character in a String - Rails

How I can delete the first "#" character of a string?

Example:

"fooo#oooooo#bar"

Expected result:

"fooooooooo#bar"

"fooo#oooooo#bar".delete_first("#") // Exist some method like this?

Upvotes: 5

Views: 3901

Answers (1)

steenslag
steenslag

Reputation: 80065

sub (not gsub) does that:

"fooo#oooooo#bar".sub('#', '') #=> "fooooooooo#bar"

Upvotes: 22

Related Questions