LoginSignup
1
0

【bat】文字列長の取得

Last updated at Posted at 2024-03-03

両端を削ってカウント
終わったら二倍・帳尻合わせ

@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
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0