[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Chopping the beginning of a string elegantly
From:       "francisrammeloo () hotmail ! com" <francisrammeloo () hotmail ! com>
Date:       2005-07-29 12:41:01
Message-ID: 1122640727.027190.79560 () f14g2000cwb ! googlegroups ! com
[Download RAW message or body]

Hi all,

I'm having some trouble finding an elegant way of removing a part of a
string based on an pattern.

Suppose I want to chop off the "Begin" in the string "BeginCaption".
My solution is this:

thePane = widgetdescription.scan( /Begin\w+/ )[0]
thePane = widgetdescription.["Begin".length..thePane.length]

Personally I don't find this method very elegant.

Can anybody offer me some hints on how to make this code more
presentable?

Also perhaps a similar strategy if I would want to remove something
from the middle or the end?

Best regards,
Francis


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic