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,
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:
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]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs