両端を削ってカウント
終わったら二倍・帳尻合わせ
@echo off
call :GET_LENGTH 123456789
echo %length%
goto :end
:GET_LENGTH
setlocal enabledelayedexpansion
set n=0
if "%~1" == "" goto :GET_LENGTH_END
set str=%~1
:GET_LENGTH_LOOP
set /a n += 1
if not "!str:~%n%,-%n%!" == "" goto :GET_LENGTH_LOOP
set /a n = %n% * 2 - 1
if not "!str:~%n%!" == "" set /a n += 1
:GET_LENGTH_END
rem echo %n% %~1
endlocal & set length=%n%
exit /b
:end
pause