中国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-11-24 06:32
47,820 topics / 349,938 posts / today 0 new / 48,298 members
DOS批处理 & 脚本技术(批处理室) » New space deletion problem??
Printable Version  3,483 / 40
Floor16 zqz0012005 Posted 2008-05-29 21:54
中级用户 Posts 135 Credits 297
Originally posted by 26933062 at 2008-5-29 09:35 PM:

Hehe, the person above really has an efficiency issue.


I also considered the efficiency issue.

Just thought of another question: Doesn't the system spend time when processing!str:~0,1! for variable truncation?

Combined with everyone's discussion, variable truncation may be more efficient than findstr.

I think Brother WANKOILZ's should still be improved.
if "!str:~0,1!"=="" echo.

[ Last edited by zqz0012005 on 2008-5-29 at 09:56 PM ]
Floor17 WANKOILZ Posted 2008-05-29 21:58
初级用户 Posts 89 Credits 198 From 重庆
Hehe, I just want to target the simple form of text by the original poster, and the method is not perfect. Piping + findstr will reduce efficiency. Of course, if you want to be comprehensive, you can only use findstr.
Floor18 amio Posted 2008-05-29 22:02
中级用户 Posts 93 Credits 206
What I have isn't simple text; it's just modifying INF files. First, help me take a look at the problem on floor 15.
Floor19 26933062 Posted 2008-05-29 22:07
银牌会员 Posts 879 Credits 2,268
Determine if there is a

@echo off&setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (a.txt) do (
set "str=%%a"
set "str=!str:




Floor20 WANKOILZ Posted 2008-05-29 22:16
初级用户 Posts 89 Credits 198 From 重庆
Remove the spaces in front of the lines at the same time:

The symbols need to be escaped with \ if used as ordinary symbols in findstr. Brothers 26 and zq ignored this, and I also discovered it after testing the previous code.

[ Last edited by WANKOILZ on 2008-5-29 at 10:27 PM ]
Floor21 26933062 Posted 2008-05-29 22:23
银牌会员 Posts 879 Credits 2,268
The code on floor 19 can remove the spaces in front of the lines...
echo %%i|findstr "^\[.*\]$">nul This method is very inefficient.
Floor22 amio Posted 2008-05-29 22:25
中级用户 Posts 93 Credits 206
Originally posted by WANKOILZ at 2008-5-29 10:16 PM:
Remove the spaces in front of the lines at the same time:
Floor23 WANKOILZ Posted 2008-05-29 22:29
初级用户 Posts 89 Credits 198 From 重庆
Reply to the upstairs: It has been improved, but it's not as easy to use as 26933062's. tokens=* ensures that the spaces before the line are removed and the subsequent data remains unchanged, which should be the best method. As for the format like findstr "^\[.*\]$">nul, I'm using it for the first time, but the format like "^[.*]$" doesn't work.
Floor24 zqz0012005 Posted 2008-05-29 22:30
中级用户 Posts 135 Credits 297
Forgot that "" are special characters in findstr

tokens=* removes leading spaces, Xiao Lou can always be innovative, really cost-effective!

[ Last edited by zqz0012005 on 2008-5-29 at 10:32 PM ]
Floor25 26933062 Posted 2008-05-29 22:35
银牌会员 Posts 879 Credits 2,268
Methods to completely match
Floor26 WANKOILZ Posted 2008-05-29 22:45
初级用户 Posts 89 Credits 198 From 重庆
The method upstairs is really unique.
But I don't understand ".*\[..*\]":
1. Why isn't ".*" added later, such as: .*\[..*\].*
2. What does the two dots mean in "..*".
Please explain it for me upstairs.
Floor27 amio Posted 2008-05-29 22:51
中级用户 Posts 93 Credits 206
There is also a problem...

Can we delete the lines starting with ; which are comments without deleting the ; in the middle of characters?

; asdasdasd
asd;asd
; qweqewqwe
---------------------------
asd;asd
Floor28 26933062 Posted 2008-05-29 22:52
银牌会员 Posts 879 Credits 2,268
* represents 0 or n repetitions of the preceding character.
. represents at least one character.
If it is ".\*\[.\*\]", then it also matches the result of [] like this. That is: the content between [] is not matched.
Floor29 WANKOILZ Posted 2008-05-29 22:57
初级用户 Posts 89 Credits 198 From 重庆
* means 0 or n repetitions of the preceding character
. means at least one character.
If it is ".*\", then it will also match results like . That is: with no content inside also matches.
It is very clear, thank you.
Also, please help again: Why not add .* at the end, in the form of ".*\.*", what is the difference between this and not adding it?

Reply to post 27: The code in post 25 meets your requirements

[ Last edited by WANKOILZ on 2008-5-29 at 10:59 PM ]
Floor30 zqz0012005 Posted 2008-05-29 23:01
中级用户 Posts 135 Credits 297
If you add .* later, then lines like [reg]add which do not end with ] will also be matched, and such lines are not what the original poster wants.
Prev  1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023