Smalltalk problem for someone - extract firstname,lastnames
The issue is to extract the firstname and lastNames from a string called fullname.
e.g. fullname of "michael john horatio bassett" -> firstname "michael" and lastnames "john horatio bassett"
Below is the code that got the job done in the short time I had, but its not a Smalltalk solution. if anyone would like to post Smalltalkish solutions that would be great.
Referring to the code below, I expect there is an easy way of taking off the first word from "fullname" and the remainder will be the lastName. Personally, what I would also really like to know is how to elegantly build the lastName string from the "names" array.
"extract first name and last name from name token" names := fullname tokenize: ' '. firstName := names at: 1. lastName := ''. (names size > 1) ifTrue: [ lastNames := names copyFrom: 2 to: (names size) -1. lastNames do: [ :ln | lastName := lastName,ln,' ' ]. lastName := lastName,(names at: names size) ]. Transcript showCr: firstName,' : ',lastName.