如何测试我的字符串是否是引号(“)。默认转义字符是'^',不是吗?
所以我尝试了以下但没有成功:
if "!first_char!" == "^"" (...)
我也试过双引号:
if "!first_char!" == """" (...)
谢谢!
如何测试我的字符串是否是引号(“)。默认转义字符是'^',不是吗?
所以我尝试了以下但没有成功:
if "!first_char!" == "^"" (...)
我也试过双引号:
if "!first_char!" == """" (...)
谢谢!
问题不在于比较的右侧部分,而在于左侧部分。由于 first_char 包含引号,因此比较的左操作数没有意义。因此,您必须使用^
包含"
.
尝试这样的事情......
if .^!first_char!.==.^". (@echo ^!first_char! YES) else (@echo ^!first_char! NO)
问题仅在比较的正确部分。
左侧的延迟扩展始终是安全的。
所以你也可以简单地在右侧使用延迟扩展,比如
set singleQuote="
if "!first_char!" == "!singleQuote!" (...)
或者,您可以转义所有引号。
if "!first_char!" == ^"^"^" (...)