Board logo

标题: 一句疑问 [打印本页]

作者: clong     时间: 2008-9-20 09:40    标题: 一句疑问

小弟在拜读了“去除变量不同部分的空格”之后,有一小疑问: 请问: set "str=%str: =%" 这句是什么意思呢?可以去除所有空格~~ 原贴地址: www.cn-dos.net/forum ...

作者: Climbing     时间: 2008-9-20 10:19
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中的所有空格替换为空(也就是去掉)。

作者: clong     时间: 2008-9-21 00:11
是懂非懂,学习。 谢谢热心的朋友!