Comment detail
文字列の反転 (Nested Flatten)文字列長を求めてから文字列を反転する方法を考えてみました。文字列が半角空白を含ま
ない場合は、引数をダブルクォーテーションで括る必要はありません。
e.g.
C:\>reverse "Hello"
olleH
C:\>reverse "こんにちは"
はちにんこ
C:\>reverse "濁点(だくてん)"
)んてくだ(点濁
遅延環境変数展開を利用しているので、Windows NTでは動作しません。Windows 2000, XP,
2003で動作を確認。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | @echo off
setlocal
set t=%1
set t=%t:"=%
call :reverse "%t%" t
echo %t%
endlocal
goto :EOF
:reverse
setlocal enabledelayedexpansion
set l=0
set r=
set t=%1
set t=%t:"=%
call :length "%t%" l
for /l %%i in (1,1,%l%) do set r=!r!!t:~-%%i,1!
endlocal & set %2=%r%
goto :EOF
:length
setlocal
set i=0
set t=%1
set t=%t:"=%
:loop
set t=%t:~1%
set /a i+=1
if not "%t%" == "" goto loop
endlocal & set %2=%i%
goto :EOF
|





pooq
#4863()
[
Batchfile
]
Rating1/1=1.00
Rating1/1=1.00-0+
1 reply [ reply ]