KevinM
KevinM

Reputation: 1807

Removing a sequence of characters from strings

In rails I simply want to remove 'http://' or 'https://' from a string if they are present. Currently I'm achieving this with the below code:

install_url.delete('http://').delete('https://')

I feel like this might not be the best way to do it. Are there any better suggestions?

Thank you!

Upvotes: 2

Views: 404

Answers (2)

BroiSatse
BroiSatse

Reputation: 44685

This should do the trick:

install_url.gsub(/https?:\/\//, '')

Upvotes: 1

rorra
rorra

Reputation: 9693

You can use regular expressions:

install_url.sub(/^http[s]?:\/\//, '')

Upvotes: 2

Related Questions