1

如何处理包含空格作为单个参数的字符串?

SET STRING=this is my teststring
call .\newFile.cmd %STRING%

newFile.cmd:
ECHO %1% //gives: "this"
4

2 回答 2

2

试试看

SET STRING=this is my teststring
call .\newFile.cmd "%STRING%"

newFile.cmd:
ECHO %~1

%~1删除周围的引号。

于 2013-07-04T11:38:46.947 回答
1

有两种方法:

1 - 在字符串周围使用引号

SET STRING="this is my teststring"

2 - 逃离空间

SET STRING=this\ is\ my\ teststring

于 2013-07-04T10:55:31.393 回答