Very Very simple problem

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

On Mon, Jul 25, 2011 at 11:03 AM, amir e. [email protected] wrote:

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

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

[0] http://ruby-doc.org/core/classes/String.html


Phillip G.

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

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

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

On Mon, Jul 25, 2011 at 4:37 AM, Mayank K.
[email protected]wrote:

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

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.

+1 for s[1…-1]

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

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

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”

On Mon, Jul 25, 2011 at 4:03 AM, amir e. [email protected] 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/.

I usually use slice!

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