Board logo

标题: [其他] 批处理字符替换是否不能用通配符? [打印本页]

作者: sgaizxt001    时间: 2010-3-18 00:27     标题: 批处理字符替换是否不能用通配符?

比如:
set str=!str:◎译  名=【中 文 名】!
set str=!str:◎片  名=【原 片 名】!
但是有些时候“◎译  名”是“◎  译  名”。此时想要用通配符,但是set str=!str:◎*片*名=【原 片 名】!完全不起作用,这里*在解释的时候好像是字符而不是通配符,写成set str=!str:◎^*片^*名=【原 片 名】!也不可以。
作者: BatCoder    时间: 2010-3-18 02:32

星号在字符串替换的时候有特殊的意义

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.

作者: sgaizxt001    时间: 2010-3-18 08:53

如果不是以*开始呢?比如:
好象按照这个意思来说我可以写成set str=!str:*片  名=【原 片 名】!,但是如果“片  名”之间的空格数不同时,仍然会启作用吗?
作者: yangfengoo    时间: 2010-3-18 09:23

明显不会,不匹配怎么替换




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2