![]() |
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-09 22:47 |
47,811 topics / 349,897 posts / today 2 new / 48,255 members |
| DOS批处理 & 脚本技术(批处理室) » Question: Organize the text (newcomers and veterans are all welcome to try) |
| Printable Version 6,471 / 54 |
| Floor1 26933062 | Posted 2008-07-13 19:51 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
### Requirements: Organize a.txt by breaking lines at periods, that is, concatenate lines without periods with the next line, and break lines with periods at the period. Note: There may be several consecutive lines without periods, or multiple periods in one line. No need to consider special character issues. Of course, the premise is that you cannot concatenate all the content of a.txt into one variable. (Because the character limit of the variable is limited) See who has the most concise and efficient code, plus points..!
### Content of a.txt: ``` Batch processing files (Batch File, referred to as BAT files) are a most commonly used executable file under DOS. It has flexible operability and can adapt to various complex computer operations. The so-called batch processing means automatically executing several specified DOS commands or programs in a prescribed order. That is to summarize the commands executed one by one, execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands. At the same time, batch processing files also have some programming characteristics. It can flexibly control the execution of the program through extended parameters, so it is very practical in daily work. Batch processing. bat. cmd. Each has its own limitations. Each has its own advantages. ``` ### Required output format: ``` Batch processing files (Batch File, referred to as BAT files) are a most commonly used executable file under DOS. It has flexible operability and can adapt to various complex computer operations. The so-called batch processing means automatically executing several specified DOS commands or programs in a prescribed order. That is to summarize the commands executed one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands. At the same time, batch processing files also have some programming characteristics. It can flexibly control the execution of the program through extended parameters, so it is very practical in daily work. Batch processing. bat. cmd. Each has its own limitations. Each has its own advantages. ``` ### Summary: There are many answers, (2nd floor 14th floor 17th floor 19th floor) The 2nd floor adopts the method of reading character by character, and can handle most special characters, but the efficiency is too low. The 14th floor created a com file, which is extremely efficient. Unfortunately, I don't understand it, but I have gained knowledge. However, this question is still solved with pure p. The ideas of the 17th floor and the 19th floor are the same, the code is slightly different, and the efficiency is also good, basically meeting the requirements of the building owner. [ Last edited by 26933062 on 2008-7-13 at 10:55 PM ] |
|
| Floor2 terse | Posted 2008-07-13 20:18 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
Read character by character
Ignore special characters, can also be simplified [ Last edited by terse on 2008-7-13 at 08:23 PM ] |
|
| Floor3 26933062 | Posted 2008-07-13 20:21 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
Reading character by character is indeed an option, but the efficiency will be greatly reduced. Add 5 points.
|
|
| Floor4 terse | Posted 2008-07-13 20:29 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
Can I replace "." with "echo."?
|
|
| Floor5 slore | Posted 2008-07-13 20:37 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
That is to summarize the originally executed commands one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands.
That is to summarize the originally executed commands one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands. How is the punctuation of this determined? |
|
| Floor6 quya | Posted 2008-07-13 20:58 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
|
It's a pity that things didn't go as expected. The final result is only one line. Experts, please help modify it. I think the idea is correct. |
|
| Floor7 HAT | Posted 2008-07-13 21:22 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Has Brother Laotu ever studied the maximum number of characters that can fit in one line of a text file? If it exceeds this limit, is your idea still correct?
|
|
| Floor8 26933062 | Posted 2008-07-13 21:44 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
Back to the 5th floor
That is, to summarize the originally executed commands one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands. There is no period in the middle, so of course it counts as one sentence. |
|
| Floor9 pusofalse | Posted 2008-07-13 21:52 |
| 银牌会员 Posts 646 Credits 1,604 | |
|
Is this okay...
@echo off&setlocal enabledelayedexpansion for /f "delims=" %%a in (a.txt) do set str=!str!%%a set str=%str:。=。^&echo.^&echo.% echo %str% pause>nul I'm sorry, I forgot to read the question in detail... [ Last edited by pusofalse on 2008-7-13 at 09:56 PM ] |
|
| Floor10 slore | Posted 2008-07-13 21:54 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
Is that a typesetting issue? I just don't understand why the Chinese characters are broken...
If it's VBS: replace "carriage return" with "empty", replace "。" with "。+carriage return" |
|
| Floor11 HAT | Posted 2008-07-13 21:54 |
| 版主 Posts 5,017 Credits 9,023 | |
|
The LZ doesn't allow this, heh heh.
|
|
| Floor12 HAT | Posted 2008-07-13 21:55 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Under Unix this should work, but under Windows it just doesn't. Thinking...
|
|
| Floor13 26933062 | Posted 2008-07-13 21:59 |
| 银牌会员 Posts 879 Credits 2,268 | |
Originally posted by slore at 2008-7-13 21:54: It's not breaking at the "中" character, it's the forum automatically wrapping it. So in my sample, empty lines represent line breaks. Is that clear? |
|
| Floor14 qzwqzw | Posted 2008-07-13 22:01 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
Change the idea
|
|
| Floor15 wxcute | Posted 2008-07-13 22:01 |
| 中级用户 Posts 211 Credits 458 | |
|
I think it might be a bug in Notepad. Sometimes it works fine, but when you close it and open it again, the Notepad will have a break in the middle.
|
|
| 1 2 3 4 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |