国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > BAT > 正文

批處理實(shí)現(xiàn)文本內(nèi)容居中顯示的代碼

2020-03-29 20:09:12
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
a.txt  
代碼:

[Promise don't come easy]
I should have known all along.
There was something wrong.
I just never read between the lines.
Then I woke up one day and found you on your way.
Leaving nothing but my heart behind.
What can I do to make it up to you.
Promises don't come easy.
But tell me if there's a way to bring you back home to stay.
Well I'd promises anything to you.
I've been walkin' around with my head hanging down.
Wondrin' what I'm gonna do.
'Cause when you walked out that door.
要求,CMD原始窗口中,不調(diào)節(jié)窗口大小,不生成臨時(shí)文件,居中顯示文本內(nèi)容。輸出如下:
代碼:


[Promise don't come easy]
I should have known all along.
There was something wrong.
I just never read between the lines.
Then I woke up one day and found you on your way.
Leaving nothing but my heart behind.
What can I do to make it up to you.
Promises don't come easy.
But tell me if there's a way to bring you back home to stay.
Well I'd promises anything to you.
I've been walkin' around with my head hanging down.
Wondrin' what I'm gonna do.
'Cause when you walked out that door.

Batcher:

sed -e :a -e "s/^./{1,77/}$/ & /;ta" a.txt

sed.exe

batman:思路說(shuō)明:
以下代碼是充分findstr命令的示例,使用findstr /n來(lái)取得行號(hào)同時(shí)兼容空行,
并將行號(hào)進(jìn)行變量賦值;使用findstr /o來(lái)取得第行的字符偏移量,但要通過(guò)
上、下行的字符偏移差,因?yàn)樽址浦凳穷?lèi)計(jì)遞加的,同時(shí)每行回車(chē)增加
兩個(gè)字符偏移,所以不可避免要對(duì)最后一行強(qiáng)加回車(chē),在不破壞原文件的情
況下只好生成臨時(shí)文件;利用findstr /o能夠一次性獲得文本所有行的字符偏
移量也就是字符總數(shù),效率和逐字符判斷相比肯定是高得多了。
---------------------------------
復(fù)制代碼 代碼如下:

@echo off
copy /y 1.txt 2.txt>nul
echo.>>2.txt&echo end>>2.txt
for /f "tokens=1,2* delims=: " %%i in ('findstr /n /o .* 2.txt') do (
set "_%%i=%%j"&set ".%%i=%%k"
  if %%i geq 2 call :lp %%i
)
del /q 2.txt&pause>nul&goto :eof
:lp
set /a n=%1-1
set /a num=_%1-_%n%-2
set /a kl=(80-num)/2
for /l %%i in (1,1,%kl%) do set /p= <NUL
call,set /p=%%.%n%%%<NUL&ECHO.
 
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大足县| 沐川县| 济南市| 建瓯市| 龙胜| 昌吉市| 东港市| 宁夏| 宜州市| 米林县| 浮梁县| 水城县| 巴林右旗| 南郑县| 苍山县| 田阳县| 吉木萨尔县| 安庆市| 简阳市| 龙川县| 甘肃省| 潼关县| 新泰市| 福州市| 布尔津县| 镇赉县| 阿荣旗| 新宾| 宾阳县| 蓬安县| 达尔| 宜兰市| 汝城县| 秦皇岛市| 谷城县| 八宿县| 眉山市| 大冶市| 那坡县| 大庆市| 阜新|