Hi!
* KONTRA Gergely; 2003-11-14, 23:30 UTC:
Is there any easiest way to get the substring starting from the 3rd
character?
my solution:
str[3..-1] which seems quite odd :-/
What if, intuitive, we can write
str[3..]?
Any smarter solution?
Besids 'get used to -1'? Well, here's some extension to 'String'. I
did try my best to follow POLS. The intention is that left, right,
mid emulate BASIC's left$, right$ and mid$ while head and tail
without any arguments have the results they should have from a
functional programming point of view.
class String
# 'number' leftmost chars
def left(number = 1)
self[0..number-1]
end
# 'number' rightmost chars
def right(number = 1)
self[-number..-1]
end
# 'number' chars starting at position 'from'
def mid(from, number=1)
self[from..from+number]
end
# chars from beginning to 'position'
def head(position = 0)
self[0..position]
end
# chars following 'position'
def tail(position = 0)
self[position+1..-1]
end
end
Josef 'Jupp' Schugt