China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 06:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to align text with bat? View 5,489 Replies 30
Floor 16 Posted 2006-12-14 02:59 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Solve:
Brother Wu Nai He, I tried your code and found that the content displayed is missing the first line. I don't know why?
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 17 Posted 2006-12-14 03:23 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
There is no problem here. Which line is missing? There is a small problem. Blank lines will also be output. Fix it.
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 18 Posted 2006-12-14 03:31 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
The new code is fine!
What does adding the if statement mean?
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 19 Posted 2006-12-14 03:43 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Originally posted by youxi01 at 2006-12-14 01:18:
Because :: can be recognized (identified as a line break) in VBS, while rem cannot be recognized by VBS!


Brother youxi01, I really didn't know there was such a usage, but I saved your code in a BAT file instead of a VBS file. I also tried saving it in VBS, but it couldn't run. Why is that again?
Floor 20 Posted 2006-12-14 04:03 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Originally posted by youxi01 at 2006-12-13 08:03:
Personally, purely P is difficult to implement because P has difficulty determining the number of bytes of variables, so it is necessary to rely on VBS.

::On Error Resume Next
echo ' > nul &cls & @echo off
echo ' > nul & ...



Can you explain the mechanism of writing and running VBS scripts in BAT? I don't understand at all how it is executed, thank you!
Floor 21 Posted 2006-12-14 04:03 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
Originally posted by ccwan at 2006-12-14 03:31:
The new code is okay!
What does adding the if statement mean?

After adding this judgment statement, blank lines will not be output. The small problem is that lines containing only spaces (blank lines) will still be output. Just change if(R != "") to if(R != "") to solve the problem of blank lines.
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 22 Posted 2006-12-14 04:07 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Thanks.
It seems necessary to learn.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 23 Posted 2006-12-14 04:41 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Brother zg159 and Brother Wunaaihe have wonderful and more general code. And using the file size to judge the number of bytes is a more convenient method.

At that time, when analyzing the three lines of code given by the owner, the code initially written according to the pattern naturally couldn't calculate the byte difference between Chinese characters and English characters. I also wanted to use the file size judgment, but out of sensitivity to generating temporary files, I only dealt with the three lines of code for 1F.

And besides Brother zh159's 8F using the file size to judge the number of bytes, there are other methods without generating temporary files. But the efficiency will be very low. In order to expand ideas and be familiar with different algorithms, everyone can try to use the following algorithm to judge Chinese characters and English characters.

1. Use for to list the characters to be matched, and once matched successfully, num+1.

2. After the FOR loop is executed, if the switch is not closed, it is judged as a Chinese character, so num+2.

3. After the entire nested loop is executed, calculate the value of num for space filling.

I hope everyone can write more wonderful code, use flexible ideas and more advanced algorithms to make up for the shortcomings of P processing script functions, and promote the development of this forum ^_^
业精于勤而荒于嬉,形成于思而毁于随。
Floor 24 Posted 2006-12-14 04:42 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Originally posted by HUNRYBECKY at 2006-12-14 03:43 AM:


Dear brother youxi01, I really didn't know there was such a usage. But I saved your code in a BAT file instead of a VBS file. I also tried saving it to VBS, but it couldn't run. Why is that?


Must be saved as a bat file because it's processed for P!
Floor 25 Posted 2006-12-14 04:46 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Originally posted by HUNRYBECKY at 2006-12-14 04:03 AM:

Can you explain the mechanism of writing and running VBS scripts in BAT? I don't understand at all how it executes. Thanks!


In P processing, lines starting with :: are ignored (considered as explanatory statements), but when it runs as VBS, it can be recognized; at the same time, in VBS, content after ' is considered as comment content......

Refer to: http://www.cn-dos.net/forum/viewthread.php?tid=25333&fpage=1&highlight=%E8%AF%86%E8%B4%A7&page=1
Floor 26 Posted 2006-12-14 05:37 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
I think the effect of awk is really good
Floor 27 Posted 2008-05-13 11:10 ·  中国 山东 烟台 联通
新手上路
Credits 4
Posts 2
Joined 2006-10-27 03:29
19-year member
UID 68440
Gender Male
Status Offline
Originally posted by youxi01 at 2006-12-13 08:03 AM:
Personally, I think that pure P is difficult to implement because P has difficulty determining the number of bytes of variables, so we need to rely on vbs.

::On Error Resume Next
echo ' > nul &cls & @echo off
echo ' > nul & ...

How to write if it is 5 columns, 6 columns?
How to output to a document in the end?
I'm a noob! Thanks!
Floor 28 Posted 2008-05-21 10:23 ·  中国 山东 烟台 联通
新手上路
Credits 4
Posts 2
Joined 2006-10-27 03:29
19-year member
UID 68440
Gender Male
Status Offline
ding! Top until the answer comes out!
Floor 29 Posted 2008-05-21 10:48 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Because the forum can't handle TAB, please change the space after!str! to TAB before running.

@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (a.txt) do (
for %%a in (%%i) do call set str=!str! %%a
echo !str:~1!&set str=
)
pause>nul
批处理之家新域名:www.bathome.net
Floor 30 Posted 2008-05-21 11:46 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Brother zw19750516, you're oversimplifying.

First, test the following code:

@echo off
echo aaaaaaa bbbbbbbbb
echo aaaaaaaa bbbbbbbbb
echo aaaaaaaaaaaaaaaaa bbbbbbbbb
pause

Moreover, it's a mix of Chinese and English...
致精致简!
Forum Jump: