Edited :
Fixed a problem in the functionhi, using command "set" to set the result to a variable, for example:
This command must be in the for command.
after that any time you can use the "%NewUserName%" in you code when you need it.
And to capitalize the result, you will need more code, there is a function here in DosTips.com (
here) that can do that you will have to add it to your code
after the "exit" commandThis is a modified one from the above function,
Code: Select all
:ToCamelCase <String> <Optional_Variable>
Set "ToCamelCaseString=%~1"
if not defined ToCamelCaseString EXIT /b
REM make all lower case
for %%a in ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i"
"J=j" "K=k" "L=l" "M=m" "N=n" "O=o" "P=p" "Q=q" "R=r"
"S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z" "?=?"
) do (
call set "ToCamelCaseString=%%ToCamelCaseString:%%~a%%"
)
call set "ToCamelCaseString= %%ToCamelCaseString%%"
REM make first character upper case
for %%a in (" a=A" " b=B" " c=C" " d=D" " e=E" " f=F" " g=G" " h=H" " i=I"
" j=J" " k=K" " l=L" " m=M" " n=N" " o=O" " p=P" " q=Q" " r=R"
" s=S" " t=T" " u=U" " v=V" " w=W" " x=X" " y=Y" " z=Z" " ?=?"
) do (
call set "ToCamelCaseString=%%ToCamelCaseString:%%~a%%"
)
call set "ToCamelCaseString=%%ToCamelCaseString: =%%"
(
IF "%~2" NEQ "" SET "%~2=%ToCamelCaseString%"
IF "%~2" EQU "" Echo %ToCamelCaseString%
)
GOTO :EOF
and you code should be like this ( i here passed the names in the order i need to the function to skip 1 step )
you can first set the name to a variable then call the function and pass that variable to it and provide a new variable name to hold the new result.:
Code: Select all
@Echo OFF
SET "Name=%userName%"
For /F "tokens=1-2 delims=." %%A In ("%Name%") Do (
Rem here we pass the result to the function to make all in one step
call :ToCamelCase "%%B.%%A" "NewUserName"
)
Rem display the result
Echo %NewUserName%
Pause
Exit
Rem Functions after this line
:ToCamelCase <String> <Optional_Variable>
Set "ToCamelCaseString=%~1"
if not defined ToCamelCaseString EXIT /b
REM make all lower case
for %%a in ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i"
"J=j" "K=k" "L=l" "M=m" "N=n" "O=o" "P=p" "Q=q" "R=r"
"S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z" "?=?"
) do (
call set "ToCamelCaseString=%%ToCamelCaseString:%%~a%%"
)
call set "ToCamelCaseString= %%ToCamelCaseString%%"
REM make first character upper case
for %%a in (" a=A" " b=B" " c=C" " d=D" " e=E" " f=F" " g=G" " h=H" " i=I"
" j=J" " k=K" " l=L" " m=M" " n=N" " o=O" " p=P" " q=Q" " r=R"
" s=S" " t=T" " u=U" " v=V" " w=W" " x=X" " y=Y" " z=Z" " ?=?"
) do (
call set "ToCamelCaseString=%%ToCamelCaseString:%%~a%%"
)
call set "ToCamelCaseString=%%ToCamelCaseString: =%%"
(
IF "%~2" NEQ "" SET "%~2=%ToCamelCaseString%"
IF "%~2" EQU "" Echo %ToCamelCaseString%
)
GOTO :EOF
The "NewUserName" now will hold the name with a capital size.
I explained it a bit fast if you need any explanation in any part of the code, just ask