[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Need help about Ruby with text file

Gavin Kistner

9/15/2006 5:52:00 PM

> 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.

3 Answers

Oscar Lok

9/16/2006 6:14:00 AM

0

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-....

Mark Woodward

9/16/2006 10:40:00 AM

0

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: http://pine.fm/LearnToProgram/?...
(Watch out for the Dragon!!!)


--
Mark

rfischer

9/2/2010 7:09:00 AM

0

Sid9 <sid9@belsouth.net> wrote:
>"M?bius Pretzel" <Mobius_A_Pretzel@yahoo.com> wrote in message
>> Record number in government anti-poverty programs
>>
>> Government anti-poverty programs that have grown to meet the needs of
>> recession victims now serve a record one in six Americans and are
>> continuing to expand.
>>
>> More than 50 million Americans are on Medicaid, the federal-state
>> program aimed principally at the poor, a survey of state data by USA
>> TODAY shows.
>>
>> That's up at least 17% since the recession began in December 2007.
>>
>> http://www.usatoday.com/news/washington/2010-08-30-1Asafetynet3...
>.
>Got a solution for this Republican recession?

The GOP solution is to throw everybody onto the streets and let them
starve.

--
Ray Fischer
rfischer@sonic.net