I need something better than split

With params[:action] = “edit_facilities”, this works…

params[:action].split(’_’)[1]

but not with params[:action] = “edit_board_volunteer” because it splits
at each underscore

How can I get everything after the first underscore character?

Craig

Craig W. wrote:

With params[:action] = “edit_facilities”, this works…

params[:action].split(’_’)[1]

but not with params[:action] = “edit_board_volunteer” because it splits
at each underscore

How can I get everything after the first underscore character?

Craig

Hi Craig,

You can try

a = params[:action]
a.split(’_’)[1…a.length]

When I try that with ‘edit_board_volunteer’, I get

s = ‘edit_board_volunteer’
=> “edit_board_volunteer”

s.split(’_’)[1…s.length]
=> [“board”, “volunteer”]

Peace,
Phillip

On 31 May 2008, at 18:25, Phillip K. wrote:

How can I get everything after the first underscore character?

Craig

Hi Craig,

You can try

a = params[:action]
a.split(’_’)[1…a.length]

or a.match(/[^]*(.*)/)[1]

Fred

On Sat, 31 May 2008 10:02:17 -0700
Craig W. [email protected] wrote:

Craig

params[:action].split(‘_’,2)

Splits into at most two array entries.

“edit_board_volunteer”.split(‘_’,2)
=> [“edit”, “board_volunteer”]

Regard,
Jon

On Sat, 2008-05-31 at 19:52 +0100, Jonathan Stott wrote:

=> [“edit”, “board_volunteer”]


bing!

much nicer/prettier than

(params[:action].split(’’)[2] == nil ? params[:action].split(’’)[1] :
params[:action].split(’’)[1] + "" + params[:action].split(’_’)[2])

Thanks

Craig