[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Strings - trying to trim values

Mmcolli00 Mom

1/22/2009 8:10:00 PM

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
--
Posted via http://www.ruby-....

2 Answers

Rob Biedenharn

1/22/2009 8:22:00 PM

0


On Jan 22, 2009, at 3:09 PM, Mmcolli00 Mom wrote:

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

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 Biedenharn http://agileconsult...
Rob@AgileConsultingLLC.com


Mmcolli00 Mom

1/23/2009 3:00:00 AM

0

Thanks Rob!
--
Posted via http://www.ruby-....