$name (string) gives something like (possible value):
John II, Litten Draw
We should update $name in two steps:
- Catch the words before first comma and throw them to the end of the string
- Remove first comma
- Create a file
current_name.txt(or update if already exists) and throw to it source of$name
“John II, Litten Draw” should be replaced with “Litten Draw John II”.
Thanks.
Here’s some sample code that should work OK:
Incidentally, this (like all of the solutions currently attached to your question) will cause data loss if there’s more than one comma in $name. As such, if this is possible you should update getCanonicalName to cater for this eventuality.