I am pulling in data from an API that provides names, but the formatting of the name puts the last name first, so “JOHN SMITH” comes in as “SMITH JOHN”. Is there a way for me to swap the order of the two words in the text?
In the strictest sense, there is no easy or good way to do this. Namely if you are expecting real first names and last names from the API that can be multi-word names like “Oscar de la Hoya” or “Bobbi Jo Johnson”.
The reason it is difficult is that you can’t use spaces to split the string because you don’t know where the first name ends and the last name starts. You can make general assumptions regarding the names to split the string, which depending on your scenario may work.
In that case you could use the split function to split by spaces like below:
This topic was automatically closed after 70 days. New replies are no longer allowed.