Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use batch processing to realize the central display of text content

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use batch processing to achieve text content center display, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

A.txt

Code:

[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.

Requirements, the original CMD window, do not adjust the window size, do not generate temporary files, center the display of text content. The output is as follows:

Code:

[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 ta 77\} $/ & /; ta" a.txt

Sed.exe

Http://xiazai.jb51.net/201010/tools/sed_jb51.rar

Batman: idea description:

The following code is an example of a full findstr command that uses findstr / n to get line numbers and be compatible with blank lines

And assign the line number as a variable; use findstr / o to get the character offset of the first line, but through the

The character offset between the upper and lower lines is different, because the character offset value is added by class calculation, and each line returns is increased.

Two characters offset, so it is inevitable to impose a carriage return on the last line without destroying the original file

In this case, we have to generate a temporary file; using findstr / o, we can get the character deviation of all lines of the text at one time.

The amount of shift, that is, the total number of characters, must be much higher than judging on a character-by-character basis.

--

The code is as follows:

@ 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 "_% iTunes% j" & set ".% iTunes%% k"

If% I geq 2 call: lp% I

)

Del / Q 2.txt&pause > nul&goto: eof

: lp

Set / a nasty% 1-1

Set / a num=_%1-_%n%-2

Set / a kl= (80-num) / 2

For / 1%% I in (1JI% KL%) do set / p =

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report