Converting a CamelCase Name to FullName FirstName LastName

Hi

I have notes that I exploded that contain the $Names of People but are in CamelCase Format in the $Name attribute.
Here are some example: TomDiaz of the $Name of one of my notes. but I have about 40 notes for future use.

I want to automate this with a stamp on my selected notes. I simply want to add a space between the CamelCase words. Here is an example of the parse I want

$FullName:Tom Diaz
$FirstName: Tom
$LastName: Diaz

How would I do this?
Thanks Tom

As you have only 40 notes, and one is TomDiaz, let’s be optimistic and assume that most of these names are going to be straightforward. If we stumble on Björk or G. E. M. de Ste. Croix, you can adjust those notes manually.

One approach would be to use the extract() operator.

The operator .extract(pattern[, ignore_case]) returns the first matched subexpression of a regular expression. If the regular expression has no subexpressions, the entire match is returned.

So, the first name is one or more characters, up to the first uppercase character. In the example, Tom.

$FirstName=$Name.extract("(.+)[A-Z]");

We could use similar logic for the last name, but I’m anxious about **Gretchen McGillicuddy **. So, having found the first name, let’s put the rest into the last name and hope for the best:

$LastName=$Name.substr($FirstName.size);
1 Like

A good time to post this useful list: Falsehoods Programmers Believe About Names - With Examples - Shine Solutions Group. FWIW, it’s not just ‘programmers’ who have these misconceptions. I’m working on a dataset with authors from all around the world. Even with spaces, it can be devilishly hard to figure out $LastName.

1 Like

Many thanks Mark. Very cool logic to use the size of the $FirstName to get the starting point of the $LastName. I learned many things today. Grateful.

One last observation: In a CamelCase name situation where TomD was used instead of the full last name, my thought I could use some error checking like if($LastName.size==0 | 1){$Color =“red”;};

Thanks again
Tom

That won’t quite work. As it happens, | binds less tightly than ==, so this is evaluated as

($LastName.size==0) | 1

This will always be true, because (anything|1) is true.

What you want is the more verbose:

$LastName.size==0 | $LastName.size==1

If you want to keep it short, you could write:

$LastName.size<=1
1 Like