forked from DoctorLai/BatchUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreverse.bat
59 lines (45 loc) · 754 Bytes
/
reverse.bat
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
@echo off
:: reverse.bat
:: http://www.zhihua-lai.com/acm
setlocal enableextensions enabledelayedexpansion
:begin
if "%1"=="-h" goto help
if "%1"=="" goto readin
goto start
:readin
(set /p _s=) && (
call :start !_s!
goto readin
) || (
goto end
)
:help
echo Usage: %0 text
shift
goto begin
goto end
:start
set _len=0
set _str=%*
:: Get the length of the sentence
set _subs=%_str%
:loop
if not defined _subs goto result
::remove the first char
set _subs=%_subs:~1%
set /a _len+=1
goto loop
:result
set /a _len-=1
for /l %%g in (0,1,%_len%) do (
call :build %%g
)
echo %s%
goto end
:build
:: get the next character
call set _digit=%%_str:~%1,1%%%
set s=%_digit%%s%
:end
endlocal