RosettaCodeData/Task/Nth/Batch-File/nth.bat

22 lines
496 B
Batchfile
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
@echo off
::Main thing...
call :Nth 0 25
call :Nth 250 265
call :Nth 1000 1025
pause
exit /b
::The subroutine
:Nth <lbound> <ubound>
setlocal enabledelayedexpansion
for /l %%n in (%~1,1,%~2) do (
set curr_num=%%n
2026-02-01 16:33:20 -08:00
if !curr_num:~-1!==1 (set "out=%%nst"
) else if !curr_num:~-1!==2 (set "out=%%n'nd"
) else if !curr_num:~-1!==3 (set "out=%%n'rd"
) else (set "out=%%n'th")
2023-07-01 11:58:00 -04:00
set "range_output=!range_output! !out!"
)
2026-02-01 16:33:20 -08:00
echo:"!range_output:~1!"
2023-07-01 11:58:00 -04:00
goto :EOF