I have scripted ParseFullName.bat in an attempt to parse a last name from a full name string.

The syntax for using ParseFullName.bat is:

ParseFullName "Full Name" GivenNamePlus LastName

Where:

"Full Name"   is a quoted string containing the full name, like "Jerold Lee Schulman".                              LastName      is a call directed environment variable that will contain the last name.                              GivenNamePlus is a call directed environment variable that will contain all but the last name.
The parsing rules, in order of precedence, are:

1. The first sub-string begins GivenNamePlus.

2. The last sub-string is the end of LastName.

3. When a sub-string is identified as part of the LastName, all subsequent sub-strings are part of LastName.

4. A sub-string that contains a comma (,) is part of LastName.

5. A sub-string that contains a period (.) is part of GivenNamePlus.

6. A single character sub-string is part of GivenNamePlus.

7. A sub-string that contains more that 2 characters is part of GivenNamePlus.

ParseFullName.bat contains:

@echo off                              if \{%3\}

\{\} @echo Syntax: ParseFullName "Full Name" GivenNamePlus LastName&exit /b1 setlocal set fn=%1 set fn=%fn:"=% set fn=%fn:,=#% for /f "Tokens=1-13" %%a in ('@echo %fn%') do ( call :name %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m ) endlocal&set %2=%fmn%&set %3=%ln% goto :EOF :name set fmn=%1 set ln= :name1 shift set work1=%1 if \{%1\}

\{\} goto err if \{%2\}

\{\} goto last1 set work2=%work1:#=,% if "%work1%" NEQ "%work2%" set work1=%work2%&goto last1 set work2=%work1:.=% if "%work1%" EQU "%work2%" goto last0 :name2 set fmn=%fmn% %1 goto name1 :last0 if not \{%3\}

\{\} goto name3 if \{%2\}

\{II\} goto last1 if \{%2\}

\{III\} goto last1 if \{%2\}

\{IV\} goto last1 if \{%2\}

\{V\} goto last1 if \{%2\}

\{VI\} goto last1 if \{%2\}

\{VII\} goto last1 if \{%2\}

\{VIII\} goto last1 :name3 if "%work1:~1,1%" EQU "" goto :name2 if "%work1:~2,1%" NEQ "" goto :name2 :last1 set ln=%work1% :last2 shift if \{%1\}

\{\} goto :EOF set ln=%ln% %1 goto last2 :err @echo Cannot parse name - %fmn% %ln% %1 %2 %3 %4 %5 %6 %7 set ln=? endlocal&set %2=%fmn%&set %3=%ln% exit /b1