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. 如何使用:gt與包含JQuery對象集合的變量
- 3. 存儲一個包含模型集合的全局變量
- 4. Laravel集合包含
- 5. 包含jsp中的變量?
- 6. Angular2 HTML結合(HTML包含變量)
- 7. 其中包含集合的類設計,其中的集合
- 8. 在MySQL中包含$變量
- 9. 包含在變量中
- 10. 包含集合在LINQ
- 11. Laravel集合不包含
- 12. MySQL包含變量
- 13. 在Python中,如何編寫一個包含集合的集合?
- 14. 集合和變量
- 15. php變量包含和html代碼包含一個php變量
- 16. 包含變量的文件
- 17. jQuery的變量包含「和」
- 18. MySQL的查詢包含PHP變量,其中包含另一個變量
- 19. Loopback Model Relation:如何在另一個集合中包含集合
- 20. Java - 如何編寫包含給定集合變量的正則表達式
- 21. 查找包含最多集合的大小爲K的集合
- 22. 如何將包含變量的文件包含在樹枝中?
- 23. Jade中的變量包含原因
- 24. C++ - 包含庫中的extern變量
- 25. 包含模板中的Jinja2變量
- 26. 包含PHP代碼的PHP變量中
- 27. 變量是空的包含文件中
- 28. 檢查域類'hasmany集合是否包含子集集合
- 29. FluentAssertions Should.Equal的集合,包含空值
- 30. LINQ排序依據包含的集合
好的謝謝,那是我更喜歡的簡單方式 – aemme 2010-10-18 09:31:14