中国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-10 16:59
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Can set replace the "*" in %str% with empty?
Printable Version  3,110 / 17
Floor1 huzixuan Posted 2007-05-04 07:45
高级用户 Posts 219 Credits 537 From 芜湖

I thought this would work, but unexpectedly it doesn't. I don't know why?
Floor2 ccwan Posted 2007-05-04 08:10
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
If you want something simpler:
Floor3 huzixuan Posted 2007-05-04 08:17
高级用户 Posts 219 Credits 537 From 芜湖
Uh, brother ccwan, one more question: in the following case, the asterisk appears randomly in the string.
If I want to replace only it, is there any other way?

Floor4 slore Posted 2007-05-04 09:13
铂金会员 Posts 2,478 Credits 5,212
http://www.cn-dos.net/forum/viewthread.php?tid=30232&fpage=2

Take a look at the part about extracting numbers in there.
Floor5 huzixuan Posted 2007-05-04 11:04
高级用户 Posts 219 Credits 537 From 芜湖
Brother slore
I looked, but didn't find a solution.
Floor6 slore Posted 2007-05-04 11:42
铂金会员 Posts 2,478 Credits 5,212
That one can extract from arbitrary characters... removing just the asterisk should be possible, right?
Floor7 ansipeter Posted 2007-05-04 15:33
中级用户 Posts 130 Credits 269
You can also try using FOR to do it, though it's rather rigid.
Floor8 ansipeter Posted 2007-05-04 16:25
中级用户 Posts 130 Credits 269
You can also try the method below; it's a bit more general than the one above.
Floor9 stornager Posted 2007-05-04 16:52
中级用户 Posts 131 Credits 328
Question for brother ansipeter: what is the use of d[] in this line, set "str=1234*567*89.d[];534*896"??
Floor10 lxmxn Posted 2007-05-04 17:11
版主 Posts 4,938 Credits 11,386
Why not use sed?
Floor11 huzixuan Posted 2007-05-05 08:41
高级用户 Posts 219 Credits 537 From 芜湖
Looks like there really isn't a good way to replace it, so I'll have to consider using tools like sed to do it.
Thanks everyone for helping little brother think of solutions!!
Floor12 digger Posted 2007-05-05 13:42
初级用户 Posts 29 Credits 79 From 湖南
Is there really no good way?
Floor13 huzixuan Posted 2007-05-05 17:20
高级用户 Posts 219 Credits 537 From 芜湖
Impressive!
What's the principle behind it?
Floor14 slore Posted 2007-05-05 22:41
铂金会员 Posts 2,478 Credits 5,212
@echo off
set "str=1234*5***sdf*67*8*9*abcd*"

:loop
for /f "delims=* tokens=1*" %%a in ("%str%") do (
if not "%%a"=="%str%" set str=%%a%%b&& goto loop
)
echo %str%
pause




Thanks to digger for the correction

[ Last edited by slore on 2007-5-5 at 11:45 PM ]
Floor15 digger Posted 2007-05-05 23:08
初级用户 Posts 29 Credits 79 From 湖南
slore's code is even more concise than mine, respect.

However, && has to be placed right after %%b, otherwise a lot of extra spaces will appear. You can see it if you use echo "%str%".
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023