English 中文(简体)
如何通过一个阵列来检查每个数值,以了解具体数值是否存在于批量中
原标题:How to loop through an array to check each value to see if specific values are present in batch

我试图打造一个能够找到用户群体成员的文字,然后检查每个群体是否在场。 为了简单起见,我用字母字母代替字母作了测试。 我设置了一个称为字母A-G的阵列,其价值为:

SETphabet=A,B,C,D,E,F,G

然后,我再造另一张称为“字母”的变量,这些数值是我想要搜索的字母阵列,看它们是否在场(我加上2个数字作为检测值,以确认它们在座右上获得的笔迹):

www.un.org/Depts/DGACM/index_spanish.htm

这里是我迄今为止所做的事情(在寻找价值观的 lo路中,使用强有力的替代):

@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET Alphabet=A,B,C,D,E,F,G
SET Letters=A,4,D,8

SET n=1
SET "MyLetter[!n!]=%Letters:,=" & SET /A n+=1 & SET "MyLetter[!n!]=%"
FOR /L %%i in (1,1,!n!) DO (
    IF "x!Alphabet:MyLetter[%%i]=!"=="x!Alphabet!" (ECHO !MyLetter[%%i]! is present) ELSE (ECHO !MyLetter[%%i]! is NOT present)
    )
ENDLOCAL

我希望文字能得出以下结果:

A is present
4 is NOT present
D is present
8 is NOT present

当你管理文字时,这是产出:

A is present
4 is present
D is present
8 is present

由于某种原因,它正在发现英文字母的阵列值为4和8。 我认为,这也许是一个与我的 lo格不入的问题,但我不敢肯定我会做什么错。 我不希望它不限制批量(但如果是,我猜想我可能不得不诉诸于“强权”),而是希望尽可能尝试和坚持纯粹的批量。 任何建议?

最佳回答

提 出

FOR %%i in (%letters%) DO (
    IF "x!Alphabet:%%i=!"=="x!Alphabet!" (ECHO %%i is NOT present) ELSE (ECHO %%i is present)
    )

理由是:

IF "x!Alphabet:MyLetter[%%i]=!"=="x!Alphabet!" (ECHO !MyLetter[%%i]! is present) ELSE (ECHO !MyLetter[%%i]! is NOT present)

页: 1 MyLetter[%i]

请注意,如果候选人IS在座,则你所用的替代方法应为alter/strong>。 因此,你的考验被逆转。

问题回答

如果你仍然希望使用现有的<条码>,用于/L方法,你可以通过添加<条码>来实现预期结果。 http://www.un.org。

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Set "Alphabet=A,B,C,D,E,F,G"
Set "Letters=A,4,D,8"

SetLocal EnableDelayedExpansion

Set "i=1"
Set "MyLetter[!i!]=%Letters:,=" & Set /A i += 1 & Set "MyLetter[!i!]=%"
For /L %%G In (1,1,!i!) Do For %%H In ("!MyLetter[%%G]!") Do If /I "!Alphabet:%%~H=!" == "!Alphabet!" (Echo %%~H is NOT present) Else Echo %%~H is present

EndLocal
Pause

EndLocal

<>说明: 我在“<代码>If的指挥中纳入了不敏感的选项,认为可以自由删除<代码>/I。 如果这是不想要的行为,。





相关问题
complex batch replacement linux

I m trying to do some batch replacement for/with a fairly complex pattern So far I find the pattern as: find ( -name *.php -o -name *.html ) -exec grep -i -n hello {} + The string I want ...

How to split a string by spaces in a Windows batch file?

Suppose I have a string "AAA BBB CCC DDD EEE FFF". How can I split the string and retrieve the nth substring, in a batch file? The equivalent in C# would be "AAA BBB CCC DDD EEE FFF".Split()[n]

How to check which Operating System?

How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....