C
Chris Causer
[Note: parts of this message were removed to make it a legal post.]
Hi everyone,
I know this is an easy question, but I want to know the best way to do this
(i.e. the most Rubyesque).
How do I strip the last four characters off a string of undetermined length?
I'm sure it is a one liner and doesn't require regexp. I currently have:
irb(main):010:0> a='80/tcp'
=> "80/tcp"
irb(main):011:0> a[0,a.length-4]
=> "80"
irb(main):010:0> b='5666/tcp'
=> "5666/tcp"
irb(main):011:0> b[0,a.length-4]
=> "5666"
Which is two lines, but I'm hoping you smart guys can help me out I'm
guessing "chop" would work, but I'm not sure if that's the most elegant
solution
Cheers,
Chris
Hi everyone,
I know this is an easy question, but I want to know the best way to do this
(i.e. the most Rubyesque).
How do I strip the last four characters off a string of undetermined length?
I'm sure it is a one liner and doesn't require regexp. I currently have:
irb(main):010:0> a='80/tcp'
=> "80/tcp"
irb(main):011:0> a[0,a.length-4]
=> "80"
irb(main):010:0> b='5666/tcp'
=> "5666/tcp"
irb(main):011:0> b[0,a.length-4]
=> "5666"
Which is two lines, but I'm hoping you smart guys can help me out I'm
guessing "chop" would work, but I'm not sure if that's the most elegant
solution
Cheers,
Chris