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"
[email protected] 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
On Jul 27, 9:13 am, Sebastian H. [email protected]
wrote:
[email protected] 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.
On Jul 27, 8:13 am, Sebastian H. [email protected]
wrote:
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