[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to truncate strings in Ruby?

Marston A.

7/21/2006 1:55:00 AM

So I'd think this is a very simple question, I've searched around the
manual and google but couldn't really find it.

So what is the method to truncate a string in Ruby? Similar to the
truncate(@text, 20) helper method in Rails? To get the first 20
characters of a string for example. Thanks in advanced

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

9 Answers

Phillip Hutchings

7/21/2006 1:57:00 AM

0

On 7/21/06, Marston A. <marston@marstononline.com> wrote:
> So I'd think this is a very simple question, I've searched around the
> manual and google but couldn't really find it.
>
> So what is the method to truncate a string in Ruby? Similar to the
> truncate(@text, 20) helper method in Rails? To get the first 20
> characters of a string for example. Thanks in advanced

Slice it, just remember it's 0 indexed.
s = '0123456789'
s = s[0..4]
=> '01234'

--
Phillip Hutchings
http://www.sit...

Logan Capaldo

7/21/2006 2:03:00 AM

0


On Jul 20, 2006, at 9:54 PM, Marston A. wrote:

> So I'd think this is a very simple question, I've searched around the
> manual and google but couldn't really find it.
>
> So what is the method to truncate a string in Ruby? Similar to the
> truncate(@text, 20) helper method in Rails? To get the first 20
> characters of a string for example. Thanks in advanced
>
> --
> Posted via http://www.ruby-....
>

@text[0...20]

@text[0, 20]

@text.slice(0, 20)

@text.slice!(0, 20) # modifies @text in place to become it's
"truncation"



Shall not be infringed

9/23/2011 1:37:00 AM

0

On Sep 22, 8:52 pm, "Stormin Mormon"
<cayoung61**spambloc...@hotmail.com> wrote:
> The Fed takes in about 2.5 trillion (what I remember) or so
> per year. Runs a deficit of a trillion or so, per year. The
> national debt is 15 trillion or so (seven or eight years
> income).
>
> If I made $25k per year, spent about 10K more than I made on
> credit cards, and had a debt of 150k or so, no one would
> consider me credit worthy.

But you don't own a printing press, do you?

RD Sandman

9/23/2011 4:35:00 PM

0

"Sid9" <sid9@ bellsouth.net> wrote in news:j5g9h6$ufj$1@dont-email.me:

>
> "RD Sandman" <rdsandman@comcast[remove].net> wrote in message
> news:Xns9F6886A3D9324hopewell@216.196.121.131...
>> "Stormin Mormon" <cayoung61**spamblock##@hotmail.com> wrote in
>> news:j5g47e $nal$1@dont-email.me:
>>
>>> With all the SS money put in the general fund, spent, and a
>>> deficit run up. Is there any evidence that the Fed profits
>>> from SS? Which would make it a Ponzi scheme?
>>
>> Possible but with the deficits being run every year, I would bet
>> against it. To me, it appears simply to be money borowed (of which
>> the payback bothers me since I doubt most of it will even occur) for
>> use as funds in other legislation.
>>
>>> Looks Ponzi to me.
>>
>>
>>
>> --
>> Sleep well tonight,
>>
>> RD (The Sandman)
>>
>> Both politicians and diapers need to be changed regularly..
>> Often for the same reason.
>
> The measure of creditworthiness is the borrowers history and assets.
> The United States has NEVER defaulted and there is no indication that
> it ever will.

Congress borrowed the money, it will be up to Congress to pay that
obligation from the general fund.

> The United States has the assets (wealth) to meet its obligations for
> the foreseeable future.

That explains why we are currently borrowing 40 cents for every dollar we
spend. ;)


> The Republican controlled congress is playing a political game.
> They'll do ANYTHING to drive the black guy in the White House out of
> office.

Take a look at the GAO and what is occuring, you ignorant twit.

> It's my opinion that Obama needs to call their bluff.
> He needs to control the timing so as to get the maximum effect before
> the November election.
> Two can play at this game

It isn't a game, mon ami. We are deep in fucking debt.


--
Sleep well tonight,

RD (The Sandman)

Both politicians and diapers need to be changed regularly..
Often for the same reason.

RD Sandman

9/23/2011 4:36:00 PM

0

Shall not be infringed <hot-ham-and-cheese@hotmail.com> wrote in
news:ba176863-d0d5-41d2-90f1-6a5c8374acb4@i14g2000prd.googlegroups.com:

> On Sep 22, 8:52?pm, "Stormin Mormon"
> <cayoung61**spambloc...@hotmail.com> wrote:
>> The Fed takes in about 2.5 trillion (what I remember) or so
>> per year. Runs a deficit of a trillion or so, per year. The
>> national debt is 15 trillion or so (seven or eight years
>> income).
>>
>> If I made $25k per year, spent about 10K more than I made on
>> credit cards, and had a debt of 150k or so, no one would
>> consider me credit worthy.
>
> But you don't own a printing press, do you?
>

Which if overused creates runaway inflation and deflation of the value of a
dollar. Do you want a five cent dollar?

--
Sleep well tonight,

RD (The Sandman)

Both politicians and diapers need to be changed regularly..
Often for the same reason.

RD Sandman

9/23/2011 6:03:00 PM

0

"Sid9" <sid9@ bellsouth.net> wrote in news:j5idr7$7os$1@dont-email.me:

>
> "RD Sandman" <rdsandman@comcast[remove].net> wrote in message
> news:Xns9F69616B6F74Bhopewell@216.196.121.131...
>> "Sid9" <sid9@ bellsouth.net> wrote in
>> news:j5g9h6$ufj$1@dont-email.me:
>>
>>>
>>> "RD Sandman" <rdsandman@comcast[remove].net> wrote in message
>>> news:Xns9F6886A3D9324hopewell@216.196.121.131...
>>>> "Stormin Mormon" <cayoung61**spamblock##@hotmail.com> wrote in
>>>> news:j5g47e $nal$1@dont-email.me:
>>>>
>>>>> With all the SS money put in the general fund, spent, and a
>>>>> deficit run up. Is there any evidence that the Fed profits
>>>>> from SS? Which would make it a Ponzi scheme?
>>>>
>>>> Possible but with the deficits being run every year, I would bet
>>>> against it. To me, it appears simply to be money borowed (of which
>>>> the payback bothers me since I doubt most of it will even occur)
>>>> for use as funds in other legislation.
>>>>
>>>>> Looks Ponzi to me.
>>>>
>>>>
>>>>
>>>> --
>>>> Sleep well tonight,
>>>>
>>>> RD (The Sandman)
>>>>
>>>> Both politicians and diapers need to be changed regularly..
>>>> Often for the same reason.
>>>
>>> The measure of creditworthiness is the borrowers history and assets.
>>> The United States has NEVER defaulted and there is no indication
>>> that it ever will.
>>
>> Congress borrowed the money, it will be up to Congress to pay that
>> obligation from the general fund.
>>
>>> The United States has the assets (wealth) to meet its obligations
>>> for the foreseeable future.
>>
>> That explains why we are currently borrowing 40 cents for every
>> dollar we spend. ;)
>>
>>
>>> The Republican controlled congress is playing a political game.
>>> They'll do ANYTHING to drive the black guy in the White House out of
>>> office.
>>
>> Take a look at the GAO and what is occuring, you ignorant twit.
>>
>>> It's my opinion that Obama needs to call their bluff.
>>> He needs to control the timing so as to get the maximum effect
>>> before the November election.
>>> Two can play at this game
>>
>> It isn't a game, mon ami. We are deep in fucking debt.
>>
>>
>> --
>> Sleep well tonight,
>>
>> RD (The Sandman)
>>
>> Both politicians and diapers need to be changed regularly..
>> Often for the same reason.
>
> Taxation and a revived economy will solve the problem.

If we also cut a lot of spending.



--
Sleep well tonight,

RD (The Sandman)

Both politicians and diapers need to be changed regularly..
Often for the same reason.

Sid9

9/23/2011 8:28:00 PM

0


"RD Sandman" <rdsandman@comcast[remove].net> wrote in message
news:Xns9F69707485E66hopewell@216.196.121.131...
> "Sid9" <sid9@ bellsouth.net> wrote in news:j5idr7$7os$1@dont-email.me:
>
>>
>> "RD Sandman" <rdsandman@comcast[remove].net> wrote in message
>> news:Xns9F69616B6F74Bhopewell@216.196.121.131...
>>> "Sid9" <sid9@ bellsouth.net> wrote in
>>> news:j5g9h6$ufj$1@dont-email.me:
>>>
>>>>
>>>> "RD Sandman" <rdsandman@comcast[remove].net> wrote in message
>>>> news:Xns9F6886A3D9324hopewell@216.196.121.131...
>>>>> "Stormin Mormon" <cayoung61**spamblock##@hotmail.com> wrote in
>>>>> news:j5g47e $nal$1@dont-email.me:
>>>>>
>>>>>> With all the SS money put in the general fund, spent, and a
>>>>>> deficit run up. Is there any evidence that the Fed profits
>>>>>> from SS? Which would make it a Ponzi scheme?
>>>>>
>>>>> Possible but with the deficits being run every year, I would bet
>>>>> against it. To me, it appears simply to be money borowed (of which
>>>>> the payback bothers me since I doubt most of it will even occur)
>>>>> for use as funds in other legislation.
>>>>>
>>>>>> Looks Ponzi to me.
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Sleep well tonight,
>>>>>
>>>>> RD (The Sandman)
>>>>>
>>>>> Both politicians and diapers need to be changed regularly..
>>>>> Often for the same reason.
>>>>
>>>> The measure of creditworthiness is the borrowers history and assets.
>>>> The United States has NEVER defaulted and there is no indication
>>>> that it ever will.
>>>
>>> Congress borrowed the money, it will be up to Congress to pay that
>>> obligation from the general fund.
>>>
>>>> The United States has the assets (wealth) to meet its obligations
>>>> for the foreseeable future.
>>>
>>> That explains why we are currently borrowing 40 cents for every
>>> dollar we spend. ;)
>>>
>>>
>>>> The Republican controlled congress is playing a political game.
>>>> They'll do ANYTHING to drive the black guy in the White House out of
>>>> office.
>>>
>>> Take a look at the GAO and what is occuring, you ignorant twit.
>>>
>>>> It's my opinion that Obama needs to call their bluff.
>>>> He needs to control the timing so as to get the maximum effect
>>>> before the November election.
>>>> Two can play at this game
>>>
>>> It isn't a game, mon ami. We are deep in fucking debt.
>>>
>>>
>>> --
>>> Sleep well tonight,
>>>
>>> RD (The Sandman)
>>>
>>> Both politicians and diapers need to be changed regularly..
>>> Often for the same reason.
>>
>> Taxation and a revived economy will solve the problem.
>
> If we also cut a lot of spending.
>
>
.
.
Cutting spending cuts jobs.
That's not what we need right now.

Right now the emphasis needs to be on jobs...not losing more of them by
cutting government programs

Shall not be infringed

9/23/2011 10:27:00 PM

0

On Sep 23, 12:36 pm, RD Sandman <rdsandman@comcast[remove].net> wrote:
> Shall not be infringed <hot-ham-and-che...@hotmail.com> wrote innews:ba176863-d0d5-41d2-90f1-6a5c8374acb4@i14g2000prd.googlegroups.com:
>
> > On Sep 22, 8:52 pm, "Stormin Mormon"
> > <cayoung61**spambloc...@hotmail.com> wrote:
> >> The Fed takes in about 2.5 trillion (what I remember) or so
> >> per year. Runs a deficit of a trillion or so, per year. The
> >> national debt is 15 trillion or so (seven or eight years
> >> income).
>
> >> If I made $25k per year, spent about 10K more than I made on
> >> credit cards, and had a debt of 150k or so, no one would
> >> consider me credit worthy.
>
> > But you don't own a printing press, do you?
>
> Which if overused creates runaway inflation and deflation of the value of a
> dollar.  Do you want a five cent dollar?

Is that like a wooden nickel?

Mick Karn

9/23/2011 10:44:00 PM

0

Shall not be infringed wrote:

> On Sep 23, 12:36 pm, RD Sandman <rdsandman@comcast[remove].net> wrote:
>
>>Shall not be infringed <hot-ham-and-che...@hotmail.com> wrote innews:ba176863-d0d5-41d2-90f1-6a5c8374acb4@i14g2000prd.googlegroups.com:
>>
>>
>>>On Sep 22, 8:52 pm, "Stormin Mormon"
>>><cayoung61**spambloc...@hotmail.com> wrote:
>>>
>>>>The Fed takes in about 2.5 trillion (what I remember) or so
>>>>per year. Runs a deficit of a trillion or so, per year. The
>>>>national debt is 15 trillion or so (seven or eight years
>>>>income).
>>
>>>>If I made $25k per year, spent about 10K more than I made on
>>>>credit cards, and had a debt of 150k or so, no one would
>>>>consider me credit worthy.
>>
>>>But you don't own a printing press, do you?
>>
>>Which if overused creates runaway inflation and deflation of the value of a
>>dollar. Do you want a five cent dollar?
>
>
> Is that like a wooden nickel?

Made on my CNC, yes.
I use Ironwood and some Krylon.
Fools the parking meters here all the time.

(shhh(!)


I figure in about 30 years, it might pay off! :/