Good question! and the answer is rather strange but true and this does not often happen:
That is not as easy as you might think, e.g. my full name is
Thaddeus Franciscus Maria De Koning. Now what is my surname and what part is my name?
Or even worse, my alter ego (an anagram for Thaddy de Koning):
Todd Hayden King. Hayden can be both surname or part of the name.
Therefor you would want to have
the user to enter name and surname in
different fields.
Basically name and surname can not be computed accurately. Humans often can, but even humans can not do that always correct (e.g. Hayden above).
A well written application has at least fields for name, prefix, suffix and surname, where prefix and suffix are optional.
You may also want fields for prefixed and suffixed titles, like Dr, subs. Ph.D, LLC etc.
I hope this example helps. Only the user can do this accurately.
You asked a simple question for which the answer is that there is
no computable solution, not even with AI... Shit happens...
Actually, that is funny, isn't it?
If the question would be reduced to swapping two strings the answer would be very easy.
Note that many "programmers" think they can solve this paradox, but that eventually always leads to data corruption.
Now you can recognize such folly...
Use multiple fields! And this is one example where a programmer must trust the user!
You've made my day to be able to explain this to some extend!
Thanks for the good question.