Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 964
Paladini Avatar asked May 17 '13 19:05

Paladini


People also ask

How do I remove the first character of a string?

To delete the first character from a string, you can use either the REPLACE function or a combination of RIGHT and LEN functions. Here, we simply take 1 character from the first position and replace it with an empty string ("").

How do I remove the first 4 characters in Excel?

The formula =RIGHT(A2,LEN(A2)-4) in cell B2 is used to remove the first four characters in the product code.


1 Answers

sub (not gsub) does that:

"fooo#oooooo#bar".sub('#', '') #=> "fooooooooo#bar"
like image 114
steenslag Avatar answered Oct 24 '22 01:10

steenslag