Tarang
Tarang

Reputation: 75945

Remove first character from Ruby string using [1..n]

I'm trying to basically trying to remove the . in the the string .extension

So I'm using

'.extension'[1..10] #gives extension

Of course this will work for 10 characters, how would I make it work for any length. I dont know what to search for because I dont know what this array style [x..y] is called.

Upvotes: 3

Views: 11039

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230316

You can use negative indexes. This will offset them from the end. -1 is the last element, -2 is the second last and so on.

'.extension'[1..-1] # => extension

Upvotes: 18

Related Questions