Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: cont'd from http://www.dostips.com/forum/viewtopic.php?f=3&t=2891&p=13349#p13349
- :: Here is the full script and output. It quits after processing the first loop:
- @echo off
- :showWinExe
- setlocal enabledelayedexpansion
- set string=arbitrary list of words that are at least this long in order to show truncation
- call :Format [-15][-15][-15] %string%
- goto :eof
- :Format fmt str1 str2 ... -- outputs columns of strings right or left aligned
- :: -- fmt [in] - format string specifying column width and alignment, i.e. "[-10][10][10]"
- :$created 20060101 :$changed 20091130 :$categories Echo
- :$source http://www.dostips.com
- SETLOCAL
- set "fmt=%~1"
- set "line="
- set "spac= "
- set "i=1"
- echo. && echo. Recieved from caller: "%*" && echo.
- for /f "tokens=1,2 delims=[" %%a in ('"echo..%fmt:]=&echo..%"') do (
- ECHO a = "[%%a]" : b = "[%%b]"
- set /a i+=1
- call call set "subst=%%%%~%%i%%%spac%%%%%~%%i%%"
- if %%b0 GEQ 0 (call set "subst=%%subst:~0,%%b%%"
- ) ELSE (call set "subst=%%subst:~%%b%%")
- call set "const=%%a"
- call set "line=%%line%%%%const:~1%%%%subst%%"
- ECHO Loop number: %i%
- )
- echo.%line%
- EXIT /b
- :: ------------ end of file ------------------
- :: output:
- B:\code>format-test.bat
- Recieved from caller: "[-15][-15][-15] arbitrary list of words that are at least this long in order to show truncation"
- a = "[.]" : b = "[-15]"
- Loop number: 1
- a = "[.]" : b = "[-15]"
- Loop number: 1
- a = "[.]" : b = "[-15]"
- Loop number: 1
- a = "[.]" : b = "[]"
- Loop number: 1
- arbitrary list of
- [/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement