批处理-搜索变量是否包含空格 [英] Batch - Search if a variable contains spaces
本文介绍了批处理-搜索变量是否包含空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个变量,需要检查它是否包含空格,如果存在则退出. 我有以下代码:
I have a variable that I need to check if it contains spaces, and exit if it does. I have this code:
if not [%VAR%]==[%VAR: =%] exit 1
..但不适用于空格.我可以将其用于其他字符.例如,查找"/"可以使用相同的代码:
.. but it does not work for spaces. I can use it for other characters though. For example looking for "/" works with same code:
if not [%VAR%]==[%VAR:/=%] exit 1
有办法吗?
谢谢
推荐答案
此操作应根据您的需要:双引号始终是空格和其他一些字符的解决方案.
This should do as you need: double quotes are always the solution for spaces, and also with some other characters.
if not "%VAR%"=="%VAR: =%" exit 1
这篇关于批处理-搜索变量是否包含空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文