Very Very simple problem

Hi
I have a string like "12345678". I want to remove first character.
How can I do this?

···

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

See if the documentation for String[0] lists a method to slice Strings.

[0] class String - RDoc Documentation

···

On Mon, Jul 25, 2011 at 11:03 AM, amir e. <aef1370@gmail.com> wrote:

Hi
I have a string like "12345678". I want to remove first character.
How can I do this?

--
Phillip Gawlowski

phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibniz

Have a look at String's slice method..
http://ruby-doc.org/core/classes/String.html#M001213

Btw, if you know it's a simple problem then you should be able to solve it
:wink:

···

--
Mayank Kohaley

On Mon, Jul 25, 2011 at 2:33 PM, amir e. <aef1370@gmail.com> wrote:

Hi
I have a string like "12345678". I want to remove first character.
How can I do this?

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

amir e. wrote:

Hi
I have a string like "12345678". I want to remove first character.
How can I do this?

Try this:

a = "012345678"
b = a[1..-1]
p b

Hello amir e.

A string is actually considered an abstract data type. Essentially
it's an array of chars. treat it as if it's an array to get the answer
to your question.

another variation of the use of ranges which others have shown you in
this thread:
x[1..(x.length)]

You could challenge yourself and write something that does it with a
method instead of a one-liner.

~Stu

···

On Mon, Jul 25, 2011 at 4:03 AM, amir e. <aef1370@gmail.com> wrote:

Hi
I have a string like "12345678". I want to remove first character.
How can I do this?

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

amir e. wrote in post #1012824:

I have a string like "12345678". I want to remove first character.
How can I do this?

irb(main):001:0> s="12345678"
=> "12345678"
irb(main):002:0> s[0,1] = ""
=> ""
irb(main):003:0> s
=> "2345678"

irb(main):004:0> s="12345678"
=> "12345678"
irb(main):005:0> s.sub!(/./,'')
=> "2345678"
irb(main):006:0> s
=> "2345678"

···

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

Since no one else has mentioned it, I thought I'd suggest a method I've found
easier to remember but clearly less efficient:

"12345678".reverse.chop.reverse

···

On Monday, July 25, 2011 04:03:15 AM amir e. wrote:

Hi
I have a string like "12345678". I want to remove first character.
How can I do this?

I usually use slice!

str = "12345678"
str.slice!(0) # => "1"
str # => "2345678"

···

On Mon, Jul 25, 2011 at 4:03 AM, amir e. <aef1370@gmail.com> wrote:

Hi
I have a string like "12345678". I want to remove first character.
How can I do this?

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

Sometimes you know it is a simple problem for people familiar with the
language (would take less than a minute to solve) but it is not a simple
problem for you (would take more than an hour to solve). In these
situations, I think it is fine to ask, it's not like you're really putting
anyone out.

···

On Mon, Jul 25, 2011 at 4:37 AM, Mayank Kohaley <mayank.kohaley@gmail.com>wrote:

Have a look at String's slice method..
class String - RDoc Documentation

Btw, if you know it's a simple problem then you should be able to solve it
:wink:
--
Mayank Kohaley

+1 for s[1..-1]

···

-----Original Message-----
From: Josh Cheek [mailto:josh.cheek@gmail.com]
Sent: Monday, July 25, 2011 10:27 AM
To: ruby-talk ML
Subject: Re: Very Very simple problem

On Mon, Jul 25, 2011 at 4:37 AM, Mayank Kohaley <mayank.kohaley@gmail.com>wrote:

Have a look at String's slice method..
class String - RDoc Documentation

Btw, if you know it's a simple problem then you should be able to
solve it
:wink:
--
Mayank Kohaley

Sometimes you know it is a simple problem for people familiar with the
language (would take less than a minute to solve) but it is not a simple
problem for you (would take more than an hour to solve). In these
situations, I think it is fine to ask, it's not like you're really
putting anyone out.