中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-25 23:35
47,812 topics / 349,910 posts / today 0 new / 48,264 members
DOS批处理 & 脚本技术(批处理室) » [Solved] Batch menu alignment problem... (that is, the problem of drawing tables)
Printable Version  1,660 / 13
Floor1 flyinspace Posted 2007-04-23 02:52
银牌会员 Posts 517 Credits 1,206
Dear experts, have you ever had the following experience~!

When making a batch processing table, if there are variables in it, such a table is always misaligned when writing. Because variables may be large or small.

Therefore, we always try to avoid using variables in the table when writing, but it is a pity to give up using variables in the table if a good batch processing is because of this.

I'm afraid it's not clear enough to say: for example.

Suppose there are several variables now.
set /p name=
set /p add=
set /p phone=
I need to draw a table on the screen.
┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ %name% %phone% ┃
┃ %add% ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Just roughly represent it like this, then how do you deal with the problem of aligning the subsequent line with the top when you encounter such a situation?
Personally, I have an immature idea.. but I encountered a problem in dealing with Chinese and non-English issues.
It is known that the line for making the table occupies two characters, Chinese characters occupy one character, and English and various symbols occupy one character.
If the variables are all English or Chinese characters, then this idea is fine..
---------------------------------------------------------------------------------------------------------
1, Suppose I want to draw 37 table lines in one line, that is, a distance of 74 characters. Among them, the table will use 4 characters.
2, The space occupied by the variable, use for /l %%i in (0,1,1000) to obtain the number of characters of the variable. Make this number of characters not greater than 35 or 70.
3, Then use 35 or 70 minus this number. Obtain the number of spaces to be drawn to get the answer for the distance of the table border line.
---------------------------------------------------------------------------------------------------------
But, frequently, the variables we write are the result of Chinese + English. Then how to correctly obtain the real number of characters of the variable.
Hehe, I hope everyone can pool their ideas. Solve this difficult problem, and also hope everyone can draw a relatively beautiful menu (table) out.


Thank you youxi01, lxmxn. Let me learn new knowledge.

One is to get the file size, and the other is character judgment, (modify the assic a bit, it should be no problem probably)

[ Last edited by flyinspace on 2007-4-22 at 06:12 PM ]
Floor2 youxi01 Posted 2007-04-23 04:47
高级用户 Posts 247 Credits 846 From 湖南==》广东
For the alignment of variables combining Chinese and English, the general approach we usually adopt is to first obtain the total number of bytes of the variable (this work is generally done by VBS, and of course, willsort seems to have also written one processed by P). Then we proceed with alignment.

The following program also uses pure batch processing to obtain the number of bytes, but special characters are not considered here. The principle is very simple: if a certain character is greater than "Z", it is considered a Chinese character (similarly, special characters are not processed).

Welcome to test and provide corrections.


The test results are as follows:

Replace the previous content and test as follows:
Floor3 lxmxn Posted 2007-04-23 05:04
版主 Posts 4,938 Credits 11,386
According to the brother's requirements, it's written. You can modify it by yourself.

Also, please everyone test.



[ Last edited by lxmxn on 2007-4-22 at 04:39 PM ]

Attachments
BatchMemu.JPG (27.09 KiB)
Floor4 bjsh Posted 2007-04-23 05:33
银牌会员 Posts 621 Credits 2,000
Brother lxmxn wrote beautifully, but the spaces are still not long enough; make them longer;

Try yours: Name: 1 Phone: 1 Address: 1; an exception will occur; lengthen the space;
Floor5 lxmxn Posted 2007-04-23 05:39
版主 Posts 4,938 Credits 11,386
Re bjsh:

Thanks brother for testing and pointing out the deficiencies. The code has been corrected.

[ Last edited by lxmxn on 2007-4-22 at 04:41 PM ]
Floor6 flyinspace Posted 2007-04-23 07:07
银牌会员 Posts 517 Credits 1,206
Thanks to the solutions from the second and third floors. It's really rewarding...

The algorithm idea of the second floor is: judge whether the character is greater than two.
And the third floor is writing to a file...

Here's a question...

>temp.tem<nul set/p=%string%

Can you explain this file writing solution? I didn't know it could be used like this originally.
Floor7 bjsh Posted 2007-04-23 07:27
银牌会员 Posts 621 Credits 2,000
>temp.tem<nul set/p=%string%

is equivalent to

set /p=%sring% <nul >temp.tem

set /p=%sring% <nul is to output %string% on the console;

Redirect to temp.tem without line break;

Usually set /p variable name=prompt string:

To get input; here <nul is used to assign an empty string;

The effect is to shield user input; only display the prompt string; often used to output without line break; at this time the variable name can be omitted

[ Last edited by bjsh on 2007-4-22 at 06:29 PM ]
Floor8 bjsh Posted 2007-04-23 07:29
银牌会员 Posts 621 Credits 2,000
Brother lxmxn used this to redirect a string without carriage returns to a file; then used %~za to get the number of bytes; at this time, of course, there is no distinction between Chinese characters and letters
Floor9 lxmxn Posted 2007-04-23 07:31
版主 Posts 4,938 Credits 11,386
Originally posted by flyinspace at 2007-4-22 18:07:
There is a question here..

>temp.tem<nul set/p=%string%

Can you explain this file writing method?

I didn't know it could be used like this before.

The function of ">temp.tem<nul set/p=%string%" is the same as "set/p=%string%>temp.tem<nul", actually it's just the position of the statement is replaced, but the function is the same.
There are many similar statements. As long as you practice and summarize carefully, there are many methods.

For example:
>1.txt echo Hello,world.
and
echo Hello,world.>1.txt
have the same function.
Floor10 lxmxn Posted 2007-04-23 07:31
版主 Posts 4,938 Credits 11,386
So it turns out that bjsh has already posted in advance, so I guess I'm just posting water.
Floor11 flyinspace Posted 2007-04-23 08:44
银牌会员 Posts 517 Credits 1,206
First, thank you both for your answers, which let me know that the >< can also be used in inverted sentences. Now there's a new method. : )
Floor12 vkill Posted 2007-04-24 00:07
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Floor13 htysm Posted 2007-04-24 00:28
高级用户 Posts 415 Credits 866
The connections of the nine-square grid. I've already seen it, but I don't understand it.
Floor14 flyinspace Posted 2007-04-25 08:38
银牌会员 Posts 517 Credits 1,206
I understand the algorithm? But what's the use of this?? It has nothing to do with the topic at all!
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023