String concat person's name

Hi,

If I have person’s name and I want to concatenate last name only, how
do I do that?(They are separated by space.)

ex)first_name last_name
ex)first_name middle_name last_name

thanks,

Daniel K. wrote:

Hi,

If I have person’s name and I want to concatenate last name only, how
do I do that?(They are separated by space.)

ex)first_name last_name
ex)first_name middle_name last_name

Use regular expressions:

irb

a = ‘first middle last’
=> “first middle last_name”

a =~ / ([^ ])$/
=> 12

$1
=> “last_name”

Stephan

Thanks Stephan!
I found out that this also works:

array = name.split(’ ')
array[array.length-1].to_s

On Jan 4, 5:27 pm, Stephan W. [email protected]

Or,

‘first middle last_name’.split.last

Jamey

On Jan 4, 2008 5:27 PM, Stephan W.
[email protected]