Triming characters from the front of a String

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

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"

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

That is just what I needed.

Thank you Sebastian and Florian

···

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

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.

···

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.