中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-08-09 19:40
47,811 主题排行 / 349,896 发帖 / 今日 1 篇 / 48,254 会员排行
DOS批处理 & 脚本技术(批处理室) » 一句疑问
可打印版本  929 / 2
第1楼 clong 发表于 2008-09-20 09:40
初级用户 发帖 54 积分 121
一句疑问
小弟在拜读了“去除变量不同部分的空格”之后,有一小疑问:
请问:
set "str=%str: =%"
这句是什么意思呢?可以去除所有空格~~

原贴地址:
http://www.cn-dos.net/forum/viewthread.php?tid=25172
第2楼 Climbing 发表于 2008-09-20 10:19
铂金会员 发帖 2,753 积分 6,962 来自 河北保定
set /?

环境变量替换已如下增强:

%PATH:str1=str2%

会扩展 PATH 环境变量,用 "str2" 代替扩展结果中的每个 "str1"。
要有效地从扩展结果中删除所有的 "str1","str2" 可以是空的。
str1" 可以以星号打头;在这种情况下,"str1" 会从扩展结果的
开始到 str1 剩余部分第一次出现的地方,都一直保持相配。

Environment variable substitution has been enhanced as follows:

%PATH:str1=str2%

would expand the PATH environment variable, substituting each occurrence
of "str1" in the expanded result with "str2". "str2" can be the empty
string to effectively delete all occurrences of "str1" from the expanded
output. "str1" can begin with an asterisk, in which case it will match
everything from the beginning of the expanded output to the first
occurrence of the remaining portion of str1.


在set "str=%str: =%"中,str相当于例子中的path,而:后面的空格相当于str1,而对应str2的是空字符串(也就是什么也没有),所以这个命令就是将str中的所有空格替换为空(也就是去掉)。
第3楼 clong 发表于 2008-09-21 00:11
初级用户 发帖 54 积分 121
是懂非懂,学习。
谢谢热心的朋友!
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023