批处理实现文本内容居中显示的代码
2010-10-11 09:07
756 查看
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原始窗口中,不调节窗口大小,不生成临时文件,居中显示文本内容。输出如下:
代码:
[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
http://xiazai.jb51.net/201010/tools/sed_jb51.rar
batman:思路说明:
以下代码是充分findstr命令的示例,使用findstr /n来取得行号同时兼容空行,
并将行号进行变量赋值;使用findstr /o来取得第行的字符偏移量,但要通过
上、下行的字符偏移差,因为字符偏移值是类计递加的,同时每行回车增加
两个字符偏移,所以不可避免要对最后一行强加回车,在不破坏原文件的情
况下只好生成临时文件;利用findstr /o能够一次性获得文本所有行的字符偏
移量也就是字符总数,效率和逐字符判断相比肯定是高得多了。
---------------------------------
代码:
[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原始窗口中,不调节窗口大小,不生成临时文件,居中显示文本内容。输出如下:
代码:
[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
http://xiazai.jb51.net/201010/tools/sed_jb51.rar
batman:思路说明:
以下代码是充分findstr命令的示例,使用findstr /n来取得行号同时兼容空行,
并将行号进行变量赋值;使用findstr /o来取得第行的字符偏移量,但要通过
上、下行的字符偏移差,因为字符偏移值是类计递加的,同时每行回车增加
两个字符偏移,所以不可避免要对最后一行强加回车,在不破坏原文件的情
况下只好生成临时文件;利用findstr /o能够一次性获得文本所有行的字符偏
移量也就是字符总数,效率和逐字符判断相比肯定是高得多了。
---------------------------------
@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.
相关文章推荐
- 批处理实现文本内容居中显示 -shell
- js实现当鼠标移到表格上时显示这一格全部内容的代码
- bootstarp modal框居中显示的实现代码
- js实现文本框文本域光标处插入图片文本的插件(并且光标在插入内容的内容后显示)
- Android UI 之居中绘制文本内容的正确方法——实现自定义一个TextView
- openWRT学习之LUCI之二访问model下lua文件实现简单的显示文本内容
- jQuery实现鼠标跟随提示层效果代码(可显示文本,Div,Table,Html等)
- JavaScript调用ajax获取文本文件内容实现代码
- JQuery获取与设置HTML元素的内容或文本的实现代码
- jQuery实现鼠标跟随提示层效果代码(可显示文本,Div,Table,Html等)
- 安卓开发-代码设置内容居中显示,设置
- VB.net实现从ListView控件中异地获取文本内容源代码
- select 控制网页内容隐藏于显示的实现代码
- 用jquery实现弹窗居中、居左、居右显示的效果(完全代码,可立即使用)
- 纯css3 实现多行显示隐藏和文本垂直居中
- iOS label显示HTML(富文本)代码 (解析)并实现高度自适应
- 1, 编写程序,当用户在文本框中输入内容之后,单机不同的按钮,能够把文半框中的内容粘贴到文本区中。“重置”按钮实现将文本框和文本区中的内容清空。界面上的文本区只能显示内容,不能让用户输入文本。运行结果
- 纯js代码实现未知宽高的元素在指定元素中垂直水平居中显示
- 利用ul,li,span,position:relative实现文本的居中显示