Q
集合中包含的变量
0
A
回答
0
:
C:\Users\preet>set val=99
C:\Users\preet>for %f in (100 99 21) do @if (%f)==(%val%) echo found it %f
found it 99
在一个批处理文件
set val=99
for %%f in (100 99 21) do @if (%%f)==(%val%) echo found it %%f
0
您可以使用for
声明来做到这一点。这里有一个脚本,它可以让你喜欢的东西运行:
myprog 456
,它会输出in set 2
:在命令行
@setlocal enableextensions enabledelayedexpansion
@echo off
for %%a in (abc 123 opl) do (
if "x%%a"=="x%1" echo in set 1
)
for %%a in (xyz 456 bnm) do (
if "x%%a"=="x%1" echo in set 2
)
@endlocal
0
而且您也不仅限于在Windows计算机中进行批处理。还有vbscript(和powershell)。这里是你如何检查使用VBScript
strVar = WScript.Arguments(0)
Set dictfirst = CreateObject("Scripting.Dictionary")
Set dictsecond = CreateObject("Scripting.Dictionary")
dictfirst.Add "abc",1
dictfirst.Add "123",1
dictfirst.Add "opl",1
dictsecond.Add "xyz",1
dictsecond.Add "456",1
dictsecond.Add "bnm",1
If dictfirst.Exists(strVar) Then
WScript.Echo strVar & " exists in first set"
ElseIf dictsecond.Exists(strVar) Then
WScript.Echo strVar & " exists in second set"
Else
WScript.Echo strVar & " doesn't exists in either sets"
End If
用法:
C:\test>cscript //nologo test.vbs abc
abc exists in first set
C:\test>cscript //nologo test.vbs xyz
xyz exists in second set
C:\test>cscript //nologo test.vbs peter
peter doesn't exists in either sets
相关问题
- 1. 包含不同类型变量的集合之间的交集
- 2. 存储一个包含模型集合的全局变量
- 3. Laravel集合包含
- 4. 包含jsp中的变量?
- 5. 其中包含集合的类设计,其中的集合
- 6. 在MySQL中包含$变量
- 7. 包含在变量中
- 8. MySQL包含变量
- 9. Laravel集合不包含
- 10. php变量包含和html代码包含一个php变量
- 11. 包含变量的文件
- 12. 集合和变量
- 13. MySQL的查询包含PHP变量,其中包含另一个变量
- 14. Loopback Model Relation:如何在另一个集合中包含集合
- 15. 如何将包含变量的文件包含在树枝中?
- 16. 变量是空的包含文件中
- 17. 包含模板中的Jinja2变量
- 18. C++ - 包含库中的extern变量
- 19. 在PHP中使用$ _GET包含变量在包含URL中
- 20. 检查域类'hasmany集合是否包含子集集合
- 21. JAXB和包含泛型的集合
- 22. 为包含集合的类实现IXmlSerializable
- 23. Backbone.js包含集合的模型视图?
- 24. 包含元素和其他集合用于构造C++的集合的集合
- 25. 包含常量和变量的路径
- 26. 包含文件中的变量未定义的变量错误
- 27. 分离标准|包含集合的集合
- 28. os.environ不包含HOST变量
- 29. 包含变量标签
- 30. 包含PHP变量到CSS
好的谢谢,那是我更喜欢的简单方式 – aemme 2010-10-18 09:31:14