[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Triming characters from the front of a String...

sketchitup@gmail.com

7/27/2007 2:36:00 PM

For the life of me I can't figure out an easy way to remove the first
couple of characters from a String. I looked in my Ruby book, searched
online, and checked the documentation for the String class. I must be
missing something obvious.

Could someone let me know if there is a method that I can use to do
this, or if there is some other trick to it.

Thanks,

The SketchUp Artist

5 Answers

Florian Groß

7/27/2007 2:54:00 PM

0

> For the life of me I can't figure out an easy way to remove the first
> couple of characters from a String. I looked in my Ruby book, searched
> online, and checked the documentation for the String class. I must be
> missing something obvious.

To remove all whitespace:
" hello world".lstrip # => "hello world"

To remove the first n characters (destructively):
str = "hello world"
str.slice!(0, 5) # => "hello"
str # => " world"


Sebastian Hungerecker

7/27/2007 3:13:00 PM

0

sketchitup@gmail.com wrote:
> For the life of me I can't figure out an easy way to remove the first
> couple of characters from a String. I looked in my Ruby book, searched
> online, and checked the documentation for the String class. I must be
> missing something obvious.
>
> Could someone let me know if there is a method that I can use to do
> this, or if there is some other trick to it.

str[x..-1] gives you str without the first x characters.


HTH,
Sebastian
--
NP: Kreator - Fatal Energy
Ist so, weil ist so
Bleibt so, weil war so

sketchitup@gmail.com

7/27/2007 3:51:00 PM

0

On Jul 27, 8:13 am, Sebastian Hungerecker <sep...@googlemail.com>
wrote:
> sketchi...@gmail.com wrote:
> > For the life of me I can't figure out an easy way to remove the first
> > couple of characters from a String. I looked in my Ruby book, searched
> > online, and checked the documentation for the String class. I must be
> > missing something obvious.
>
> > Could someone let me know if there is a method that I can use to do
> > this, or if there is some other trick to it.
>
> str[x..-1] gives you str without the first x characters.
>
> HTH,
> Sebastian
> --
> NP: Kreator - Fatal Energy
> Ist so, weil ist so
> Bleibt so, weil war so

That is just what I needed.

Thank you Sebastian and Florian

Phrogz

7/27/2007 3:56:00 PM

0

On Jul 27, 9:13 am, Sebastian Hungerecker <sep...@googlemail.com>
wrote:
> sketchi...@gmail.com wrote:
> > For the life of me I can't figure out an easy way to remove the first
> > couple of characters from a String. I looked in my Ruby book, searched
> > online, and checked the documentation for the String class. I must be
> > missing something obvious.
> str[x..-1] gives you str without the first x characters.

And
str[0..4]=''
will replace the first 5 characters in the string with an empty
string.

Likewise
str.sub!( /\A.{5}/m, '' )
will mutate the original string to replace the first 5 characters with
an empty string.

Stewart

9/19/2010 6:52:00 PM

0


"The Peeler" <peelingthe@invalid.admin> wrote in message
news:vg0c961j2dp8ai7d0lgb678udgj4mrinn3@4ax.com...
> On Sun, 19 Sep 2010 08:21:54 -0400, "Stewfart" <got_anus@gmail.com>
> wrote:
>
>>
>>"The Peeler" <peelingthe@invalid.admin> wrote in message
>>news:rnia96l4i3rb5176agphl884gqallh6nar@4ax.com...
>>> On Sat, 18 Sep 2010 07:58:08 -0400, "Stewfart"
>>> <got_anus@gmail.com>
>>> wrote:
>>>
>>>>
>>>>"The Peeler" <peelingthe@invalid.admin> wrote in message
>>>>news:ovsq8690gmd3ma7iqp5jq0nu734ogp7qj3@4ax.com...
>>>>> On Sun, 12 Sep 2010 17:54:58 -0400, "Stewfart"
>>>>> <got_anus@gmail.com>
>>>>> wrote:
>>>>>
>>>>>>
>>>>>>"The Peeler" <peelingthe@invalid.admin> wrote in message
>>>>>>news:p8fp86lvaeefgk2mfcf7gvaf7c3j6ooun2@4ax.com...
>>>>>>> On Sun, 12 Sep 2010 07:21:24 -0400, "Stewfart"
>>>>>>> <got_anus@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>>
>>>>>>>>"The Peeler" <peelingthe@invalid.admin> wrote in message
>>>>>>>>news:7hpn86ludbjt6atbh629a2cuor4a3iei57@4ax.com...
>>>>>>>>> On Sat, 11 Sep 2010 15:21:15 -0400, "Stewfart"
>>>>>>>>> <got_anus@gmail.com>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>"The Peeler" <peelingthe@invalid.admin> wrote in message
>>>>>>>>>>news:3hrm86dvnhen8guaj4uk2h11n6t6832424@4ax.com...
>>>>>>>>>>> On Sat, 11 Sep 2010 07:34:23 -0400, "Stewfart"
>>>>>>>>>>> <got_anus@gmail.com>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>"The Peeler" <peelingthe@invalid.admin> wrote in message
>>>>>>>>>>>>news:r0si86p1nfbv5ggbkegba485jh0eq3pbni@4ax.com...
>>>>>>>>>>>>> On Thu, 9 Sep 2010 19:31:57 -0400, "Stewfart"
>>>>>>>>>>>>> <got_anus@gmail.com>
>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>"The Peeler" <peelingthe@invalid.admin> wrote in message
>>>>>>>>>>>>>>news:9o6g86lpapd0t1aqqiorhhpkt4btn2mbse@4ax.com...
>>>>>>>>>>>>>>> On Wed, 8 Sep 2010 19:00:28 -0400, "Stewfart"
>>>>>>>>>>>>>>> <got_anus@gmail.com>
>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>"The Peeler" <peelingthe@invalid.admin> wrote in
>>>>>>>>>>>>>>>>message
>>>>>>>>>>>>>>>>news:utqe8695ri8m5sk4c4q5iuubd7dv8a9ubi@4ax.com...
>>>>>>>>>>>>>>>>> On Tue, 7 Sep 2010 19:23:56 -0400, "Stewfart"
>>>>>>>>>>>>>>>>> <got_anus@gmail.com>
>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>"The Peeler" <peelingthe@invalid.admin> wrote in
>>>>>>>>>>>>>>>>>>message
>>>>>>>>>>>>>>>>>>news:v62b86lkqp1dluhejllpnrolmu25imsf85@4ax.com...
>>>>>>>>>>>>>>>>>>> On Mon, 6 Sep 2010 16:43:40 -0400, "Stewfart"
>>>>>>>>>>>>>>>>>>> <got_anus@gmail.com>
>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>"The Peeler" <peelingthe@invalid.admin> wrote in
>>>>>>>>>>>>>>>>>>>>message
>>>>>>>>>>>>>>>>>>>>news:ebt9861o9nmi2m2q0dsqdqidt1aq58rt2u@4ax.com...
>>>>>>>>>>>>>>>>>>>>> On Mon, 6 Sep 2010 09:50:51 -0400, "Stewfart"
>>>>>>>>>>>>>>>>>>>>> <got_anus@gmail.com>
>>>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>"The Peeler" <peelingthe@invalid.admin> wrote in
>>>>>>>>>>>>>>>>>>>>>>message
>>>>>>>>>>>>>>>>>>>>>>news:4c828fd8$3@news.x-privat.org...
>>>>>>>>>>>>>>>>>>>>>>> On Sat, 04 Sep 2010 22:23:26 +0800,
>>>>>>>>>>>>>>>>>>>>>>> Hallucinating
>>>>>>>>>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>>>>>>>>>> Retard,
>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>> resident
>>>>>>>>>>>>>>>>>>>>>>> psychopath of sci and scj, IMPERSONATING his
>>>>>>>>>>>>>>>>>>>>>>> master,
>>>>>>>>>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>>>>>>>>>> Peeler,
>>>>>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>You do not have the skill set necessary for
>>>>>>>>>>>>>>>>>>>>>>>>>passing
>>>>>>>>>>>>>>>>>>>>>>>>>judgments
>>>>>>>>>>>>>>>>>>>>>>>>>of
>>>>>>>>>>>>>>>>>>>>>>>>>literacy.
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> You do not have the literacy necessary for
>>>>>>>>>>>>>>>>>>>>>>>> passing
>>>>>>>>>>>>>>>>>>>>>>>> judgments
>>>>>>>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>>>>>>>> skill
>>>>>>>>>>>>>>>>>>>>>>>> sets, jewboy. Shabbat shalom!
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> You were waiting for his post all day long,
>>>>>>>>>>>>>>>>>>>>>>> eh,
>>>>>>>>>>>>>>>>>>>>>>> poor
>>>>>>>>>>>>>>>>>>>>>>> miserable
>>>>>>>>>>>>>>>>>>>>>>> housebound
>>>>>>>>>>>>>>>>>>>>>>> The Retard. You are simply incredible! But
>>>>>>>>>>>>>>>>>>>>>>> there
>>>>>>>>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>>>>>>>>> are:
>>>>>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>>>>>>> your
>>>>>>>>>>>>>>>>>>>>>>> retardation and "splendour" !!!!
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> ROTFLOL
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>I've got her down to 7 minute responses now. A
>>>>>>>>>>>>>>>>>>>>>>very
>>>>>>>>>>>>>>>>>>>>>>silly,
>>>>>>>>>>>>>>>>>>>>>>little
>>>>>>>>>>>>>>>>>>>>>>person she is.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> All the faster to shit all over you again, jew
>>>>>>>>>>>>>>>>>>>>> cunt.
>>>>>>>>>>>>>>>>>>>>> LOL
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>17 minutes, your [sic] slipping.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> You're illiterate.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>Still within the 20 required, but your
>>>>>>>>>>>>>>>>>>>>standard deviation just went up, and your process
>>>>>>>>>>>>>>>>>>>>capability
>>>>>>>>>>>>>>>>>>>>is
>>>>>>>>>>>>>>>>>>>>down.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> You know you simply can't wait to get shat upon
>>>>>>>>>>>>>>>>>>> again,
>>>>>>>>>>>>>>>>>>> jewboy!
>>>>>>>>>>>>>>>>>>> Quit
>>>>>>>>>>>>>>>>>>> kvetching already!
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>Almost 4 hours....you must remember your training,
>>>>>>>>>>>>>>>>>>grasshopper.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Anxious to get shat upon again, jewboy?
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>Almost 12 hours. Your standard deviation is rising,
>>>>>>>>>>>>>>>>young
>>>>>>>>>>>>>>>>lady.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Really anxious to get shat upon again, jewboy? You
>>>>>>>>>>>>>>> know
>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>> makes
>>>>>>>>>>>>>>> sense!
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>24 minutes....better, but not great. You'd better shape
>>>>>>>>>>>>>>up,
>>>>>>>>>>>>>>missy.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Here comes the next dump, jewboy! Right on your head!
>>>>>>>>>>>>
>>>>>>>>>>>>Only 8 minutes to formulate another literary masterpiece.
>>>>>>>>>>>>The
>>>>>>>>>>>>lease
>>>>>>>>>>>>[sic]
>>>>>>>>>>>>is quite short.........
>>>>>>>>>>>
>>>>>>>>>>> You'll have to be quicker than that, jewboy.
>>>>>>>>>>
>>>>>>>>>>No, not really.
>>>>>>>>>
>>>>>>>>> Yes, really.
>>>>>>>>>
>>>>>>>>>>You're the one that seems to care enough to formulate
>>>>>>>>>>a rapid response, no matter how ignorant it may be. It is
>>>>>>>>>>like
>>>>>>>>>>you
>>>>>>>>>>just can't wait to show off how little you know.
>>>>>>>>>
>>>>>>>>> Like I said, jewboy, the sooner you reply the sooner I can
>>>>>>>>> shit
>>>>>>>>> all
>>>>>>>>> over you again. You got a problem with that?
>>>>>>>>>
>>>>>>>>>>> You don't want to wait
>>>>>>>>>>> all day for that dump to land on your head, do you? And
>>>>>>>>>>> what
>>>>>>>>>>> the
>>>>>>>>>>> fuck does your lease have to do with anything, you
>>>>>>>>>>> illiterate
>>>>>>>>>>> asshole?
>>>>>>>>>>
>>>>>>>>>>Your lease of intelligence, it seems you should have kept it
>>>>>>>>>>for
>>>>>>>>>>a
>>>>>>>>>>longer term.
>>>>>>>>>
>>>>>>>>> Lame, jewboy, very lame. You meant "leash" but you were too
>>>>>>>>> illiterate to spell it properly. Or you thought it was the
>>>>>>>>> same
>>>>>>>>> word
>>>>>>>>> as "lease". Either way, you're an ignorant asshole.
>>>>>>>>
>>>>>>>>From your feeble rants it is quite obvious that I am correct.
>>>>>>>
>>>>>>> From your lame response it is quite obvious that you're not.
>>>>>>>
>>>>>>>>67 minutes is outside of the predetermined limits. Please
>>>>>>>>pick
>>>>>>>>up
>>>>>>>>the
>>>>>>>>pace.
>>>>>>>
>>>>>>> You're really desperate to get shat on, aren't you, jewboy?
>>>>>>
>>>>>>You poor thing, you may be full of shat....but your problem is
>>>>>>you
>>>>>>can't expel it, let alone aim it.
>>>>>
>>>>> You ignorant jew asshole, it's all over you but you're so used
>>>>> to
>>>>> the
>>>>> smell that you don't even notice!
>>>>
>>>>It seems the "smell" emanates from your neck of the woods, and
>>>>everyone notices. But do try to keep to the >20 minute response
>>>>criteria.
>>>
>>> No, the smell is definitely coming from you, jewboy. You're a
>>> jew,
>>> after all! No question!
>>
>>Well yes, I am a Jew.
>
> Phew. That's disgusting. Go and take a wash. Even a shower.
> <snigger>
>
>>That in itself is enough to make me right and
>>you wrong. Now almost 12 hours for a response is not acceptable.
>>Please pick up the pace.
>
> You're in luck. I can shit all over you almost immediately! Don't
> wait so long next time, eh!

10 minutes...your lease is short.