Forum: Ruby Strings - trying to trim values

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mmcolli00 M. (Guest)
on 2009-01-22 22:11
What is the correct way to trim off the the first 37 characters of a
string?

I want to trim off the value from position 0 -> pos 37 or take off all
characters from right side and stopping at a specific character #.

myval = wererwerwerwerweritop123233434345556#personID

How is this done? Thanks.
MC
Rob B. (Guest)
on 2009-01-22 22:24
(Received via mailing list)
On Jan 22, 2009, at 3:09 PM, Mmcolli00 Mom wrote:

> --
Several ways:

irb> myval = 'wererwerwerwerweritop123233434345556#personID'
=> "wererwerwerwerweritop123233434345556#personID"
irb> myval[37..-1]
=> "personID"
irb> myval.split('#',2).last
=> "personID"
irb> myval[/[^#]*\z/]
=> "personID"

Take your pick!

-Rob

Rob B.    http://agileconsultingllc.com
removed_email_address@domain.invalid
Mmcolli00 M. (Guest)
on 2009-01-23 05:01
Thanks Rob!
This topic is locked and can not be replied to.