FullName := 'Name Name2 Nam3 Surname'; if StrPos(FullName, ' ') <> 0 then LastName := SelectStr(StrLen(DelChr(FullName, DelChr(FullName, '=', ' '))) + 1, ConvertStr(FullName, ' ', ',')); else LastName := FullName;SelectStr returns the specified element from a comma separated string.
StrLen(DelChr(FullName, DelChr(FullName, '=', ' ')))returns the number of spaces in the name
ConvertStr(FullName, ' ', ',')replaces spaces in the name with commas for SelectStr to work
Answers
if the string has the format you have defined (with spaces between each word) then you can start looping from last char until you find a blank space, char by char
repeat until?
And +1 gives you the number of names, because there's always more names than spaces replaces spaces in the name with commas for SelectStr to work
And we need to add a check that there really are spaces in the name (maybe incorrect data entry, or a case of mononym)
this ensures you always get the last word.