![Board logo](images/default/logo.gif)
标题: [文本处理] 批处理让输出的字符串居中(英文) [打印本页]
作者: 小竹 时间: 2008-1-7 21:09 标题: 批处理让输出的字符串居中(英文)
- @echo off
- setlocal enabledelayedexpansion
- set colsnum=70
- set linesnum=22
- MODE con: COLS=%colsnum% lines=%linesnum%
- ::首先将行数和列数都用变量表示
- title Driver Initial
- color 3F
- cls
- set/a colsnum=%colsnum%-5
- ::echo以及其后的空格共占5列
- set myecho=Driver Initial
- ::将你要输出的字符串赋值给变量myecho
- set flag=0
- ::初始化计数器flag
- for /l %%i in (0,1,1000) do (
- set tt=!myecho:~%%i,1!
- if "!tt!" equ "" goto next
- set/a flag=!flag!+1
- )
- ::统计你输入的字符串长度
- :next
- set/a colsnum=!colsnum!-!flag!
- set/a colsnum=!colsnum!/2
- for /l %%i in (1,1,!colsnum!) do (
- set space= !space!
- )
- ::得到字符串前面的n个空格
- echo.
- echo ----------------------------------------------
- echo !space!%myecho%
- echo ----------------------------------------------
- echo.
- echo 操作完毕,按任意键退出...
- pause>nul
- exit
复制代码
作者: 随风 时间: 2008-1-7 21:24
建议发代码时,用code把代码扩起来
具体使用方法如下:
http://youxi01.vip2.92idc.com/vi ... &extra=page%3D1
作者: somebody 时间: 2008-1-29 00:11
我也来个全角版的:- @echo off
- title code by somebody
- color 0b
- cls
- echo.
- :: →→→→→→→→→→→→→ Loading The Program ←←←←←←←←←←
- setlocal EnableDelayedExpansion
- (set,=Loading the program, please wait a minute&for /l %%c In (0,1,42)do @call set/p=%%,:~%%c,1%%<nul)&set,=&ping -n 2 127.1>nul&set/p="."<nul&ping -n 2 127.1>nul&set/p="."<nul&ping -n 2 127.1>nul&set/P="."<nul&ping -n 2 127.1>nul
- cls
- echo.
- set/p= Loading <nul
- for /l %%s in (1,1,15) do (
- set/p="-"<nul
- for /l %%i in (1,1,100) do ver>nul
- set/p=<nul
- for /l %%i in (1,1,100) do ver>nul
- set/p="\"<nul
- for /l %%i in (1,1,100) do ver>nul
- set/p=<nul
- for /l %%i in (1,1,100) do ver>nul
- set/p="|"<nul
- for /l %%i in (1,1,100) do ver>nul
- set/p=<nul
- for /l %%i in (1,1,100) do ver>nul
- set/p="/"<nul
- for /l %%i in (1,1,100) do ver>nul
- set/p=<nul
- for /l %%i in (1,1,100) do ver>nul
- )
- cls
-
- set num=20
- set a==
- set n=1
- for /l %%i in (1,1,80) do (
- cls
- set /a num+=1
- echo !num!%%
- echo !a!
- set a=!a!=
- set /a n+=1
- for /l %%j in (1,1,150) do ver>nul
- )
- ping -n 1 127.1 >nul 2>nul
- echo Loading Complete
- ping -n 2 127.1 >nul 2>nul
- endlocal
- cls
-
- setlocal EnableDelayedExpansion
- rem 每一行的字符串最长是34个中文字符,或者68个英文字符,不可以包含空格。
- rem 不可以混合使用半角和全角字符。只接受中文或者全角字符(即双字节字符)或者英文字符(即单字节字符)
- set "str1=超级版主:SOMEBODY"
- set "str2=积分:八二八"
- set "str3=VB币:八一五枚 "
- set "str4=好评:十二度"
- set "str5=威望:二十一点"
- set /a num=1
- for %%a in (%str1%,%str2%,%str3%,%str4%,%str5%) do (
- setlocal EnableDelayedExpansion
- set /a count=0
- set blank=
- set "b=%%a"
- for /l %%k in (0,1,68) do if not "!b:~%%k,1!"=="" set /a count+=1
- rem 处理纯半角字符串,则以下的 count 不需要乘以2
- set /a "total=(70-!count!*2)/2"
- for /l %%i in (1,1,!total!) do set "blank=!blank! "
- set "final=│!blank!!b!!blank!│"
- set newstr!num!=!final!
- set /a num+=1
- )
- :print
- setlocal EnableDelayedExpansion
- set a=┌───────────────────────────────────┐
- set "b=%newstr1%"
- set c=├───────────────────────────────────┤
- set "d=%newstr2%"
- set e=├───────────────────────────────────┤
- set "f=%newstr3%"
- set g=├───────────────────────────────────┤
- set "h=%newstr4%"
- set i=├───────────────────────────────────┤
- set "j=%newstr5%"
- set k=└───────────────────────────────────┘
- for %%i in (a b c d e f g h i j k) do (
- set/p= <nul
- for /l %%a in (0,1,100) do (
- if not "!%%i:~%%a,1!"=="" (
- if %%a==100 echo.&echo;
- set/p=!%%i:~%%a,1!<nul
- for /l %%i in (1,1,50) do ver>nul
- )
- )
- echo.
- )
- pause
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |