Need help about Ruby with text file

By the way, may I know that is there any function like e.g.
left(line,
3), right(line, 2) and mid(line, 1, 4) to extract letter from a line,
please?
e.g.
mid(gghhii,3,2) return hh
left(gghhii,3) return ggh
right(gghhii,3) return hii

Remember that arrays and strings start at index 0, not index 1.

str = "gghhii"
p str[ 0, 3 ] #=> "ggh"
p str[ -3, 3 ] #=> "hii"
p str[ 2, 2 ] #=> "hh"

class String
  def left( chars )
    self[ 0, chars ]
  end
  def right( chars )
    self[ -chars, chars ]
  end
  def mid( start, chars )
    self[ start, chars ]
  end
end

p str.left( 3 ) #=> "ggh"
p str.right( 3 ) #=> "hii"
p str.mid( 2, 2 ) #=> "hh"

For more ways to manipulate strings, please type "ri String" into your
prompt.

Hai, Gavin Kistner

Thanks for your reply!
Somebody talk about "Class" in Ruby to me.
May I know that is "Class" a way to make my own fucntion only, please?
Am I right? If not, what else "Class" can do?
Your reply give me a new thought to do script with my way!

Thanks
Regards
Oscar

···

--
Posted via http://www.ruby-forum.com/.

Hi Oscar,

···

On Sat, 16 Sep 2006 15:13:56 +0900, Oscar Lok wrote:

Hai, Gavin Kistner

Thanks for your reply!
Somebody talk about "Class" in Ruby to me.
May I know that is "Class" a way to make my own fucntion only, please?
Am I right? If not, what else "Class" can do?
Your reply give me a new thought to do script with my way!

Thanks
Regards
Oscar

'Class' is a big topic!
Maybe start here: Classes - Learn to Program
(Watch out for the Dragon!!!)

--
Mark