I have the following code and results, and I cannot work out why the capitalization of the first letter is not holding.
Code
@echo off
set /P "PrimaryApplicantFirst=Enter First Name: "
call :toUpperFirst %PrimaryApplicantFirst%
echo %PrimaryApplicantFirst%
pause
------------------------------------------------------------------------
:toUpperFirst str
SETLOCAL ENABLEDELAYEDEXPANSION
set "name=%~1"
set first_letter=%name:~0,1%
set last_letters=%name:~1%
for %%# in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
set first_letter=!first_letter:%%#=%%#!
)
set "PrimaryApplicantFirst=%first_letter%%last_letters%"
echo %PrimaryApplicantFirst%
SETLOCAL DISABLEDELAYEDEXPANSION
EXIT /b
Inputting "test" will result in
Test
test
Why is this the case?
EDIT - The following also produces the error. Am I missing something?
:toUpperFirst var
setlocal enableDelayedExpansion
set "name=!%~1!"
set first_letter=%name:~0,1%
set last_letters=%name:~1%
for %%# in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
set first_letter=!first_letter:%%#=%%#!
)
set "PrimaryApplicantFirst=%first_letter%%last_letters%"
endlocal && (
set "%~1=%PrimaryApplicantFirst%"
)
exit /b %errorlevel%