Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理数组、关联数组以及如何在数组中导航_Batch File_Arraylist_Cmd_Logic_Delayedvariableexpansion - Fatal编程技术网

Batch file 批处理数组、关联数组以及如何在数组中导航

Batch file 批处理数组、关联数组以及如何在数组中导航,batch-file,arraylist,cmd,logic,delayedvariableexpansion,Batch File,Arraylist,Cmd,Logic,Delayedvariableexpansion,如何批量调用多级数组 我想用多个数据创建一个具有唯一值的数组,然后在取消对值的YFY运算后,我将设法创建一个关联数组 我有一个csv文件,它的价值如下: R14201;03h22mn55s;profile;15; R14201;03h23mn02s;profile,15; R14201;03h23mn07s;home;15; R14202;03h23mn12s;profile;12; R14201;03h23mn16s;home;14; R14203;03h23mn19s;profile;15;

如何批量调用多级数组

我想用多个数据创建一个具有唯一值的数组,然后在取消对值的YFY运算后,我将设法创建一个关联数组

我有一个csv文件,它的价值如下:

R14201;03h22mn55s;profile;15;
R14201;03h23mn02s;profile,15;
R14201;03h23mn07s;home;15;
R14202;03h23mn12s;profile;12;
R14201;03h23mn16s;home;14;
R14203;03h23mn19s;profile;15;
R14203;03h23mn22s;profile;11;
R14201;03h23mn25s;profile;15;
R14204;03h23mn31s;profile;12;
...
我想做什么:

1-获得RXXX的唯一参考(成功)

2-参见第三列中的更改,仅更改及其顺序

3-参见最后一列的不同值

因此,最终,欲望状态将是:

R14201 : [profile, home, profile], [15, 14]
R14202 : [profile], [12]
R14203 : [profile], [15, 11]
R14204 : [profile], [12]
在变量方面,我将有如下内容:

myArray[R14201].NAME=R14201
myArray[R14201].PROFILE[0]=profile
myArray[R14201].PROFILE[1]=home
myArray[R14201].PROFILE[2]=profile
myArray[R14201].NUMBER[0]=15
myArray[R14201].NUMBER[1]=14


myArray[R14202].NAME=R14202
myArray[R14202].PROFILE[0]=profile
myArray[R14202].NUMBER[0]=12

myArray[R14203].NAME=R14203
...
编辑:

在逻辑方面,我认为我将有两个数组:我的关联数组和另一个访问我的关联数组:

myIteratorArray[0]=R14201
myIteratorArray[1]=R14202
myIteratorArray[2]=R14203
myIteratorArray[3]=R14204
...
myArray[R14201].NAME=R14201
myArray[R14201].PROFILE[0]=profile
...
现在我只是试着理解并批量设置我的数组,我是在3天前学习语言的

但事实是:我知道通过EnableDelayedExtension,我可以使用2个叠瓦变量,但我不知道我是否可以有3个或更多的叠瓦变量

多亏了on,我成功地理解了有关批处理阵列的许多内容

在下面的代码中,进入第二个for,我不知道如何调用该变量

@echo off
setlocal EnableDelayedExpansion

set i=0
for %%d in (R14201 R14201 R14201 R14202 R14201 R14203 R14203 R14201 R14204) do (
    :: Here I see if myArray[RXXX] is defined
    if not defined myArray[%%d] (
        set /A i=i+1
        set myArray[%%d]=x!i!
        :: Here I set an other array in order to loop on this array, to call myArray[RXXX]
        :: I will call myArray[RXXX] and RXXX will be stored in myIteratorArray[x].
        :: I am sure that myIteratorArray[x] will contain unique value thanks to the if condition
        set myIteratorArray[!i!]=%%d
    )
)

set numberOfJu=%i%

for /L %%i in (1, 1, %numberOfJu%) do (
    ::here the problematic call
    echo !myArray[!myIteratorArray[%%i]!]!
)
这里是我的问题:

1-如何调用具有多个重叠变量(如myArray[myIteratorArray[myIndex])的变量

为了成功,你认为我的逻辑是什么

3-你认为可以批量完成吗?我没有选择的语言


提前谢谢

当需要延迟扩展才能访问的变量由额外的延迟变量组成时,可以使用额外的for循环访问子变量:

for/L%%i in(1,1,%numberOfJu%)do for/f“Delims=“%%u in(“!myIteratorArray[%%i]!”)do(
echo!myArray[%%u]!
)
对于使用每个唯一值定义数组,可以使用findstr在定义过程中将该值添加到数组之前,搜索数组的相关组以查找该值的存在

有关批量处理关联数组的高级示例,请参见 上面是一个批量RPG游戏的模板,它使用关联数组来处理与库存相关的所有问题,每个项目都有相关的值,例如值、重量dmg/防御等,只要项目通过迭代装备组进行更改,这些值就会更新

下面是一个简短的脚本,演示了如何定义可以使用
findstr
搜索的数组,以实现有序输出:

@Echo-off&Cd/d“%~dp0”
Setlocal EnableDelayedExpansion
:#将“source.csv”替换为csv文件的路径
对于/F“Delims=“%G in(Source.csv)Do For/F”标记=1,3,4 Delims=;”,“%1 in(“%G”)Do(
Echo(!$Refs!|%uu APPDIR_uuu%Findstr.exe/c:“%1”>nul |(
设置“$Refs=!$Refs!%%1”
)
设置/A“%%1[i]+=1”
rem比较上次定义的[参考]
对于/f“Delims=“%%v in('Set/A”!%%1[i]!-1”)执行以下操作(
如果不是“!Ref[%%1][%%v]!”==“%%3”(
设置/A“[i]+=1”
设置“Ref[%%1][!%%1[i]!]=%%3”
设置/A“参考[%%1]+=1”
设置“$Ref[![i]!]%%1[!Ref[%%1]!]。%%2=%%3”
)否则(
设置/A%%1[i]=1
)))
对于%%G in(!$Refs!)为/f“代币=1,2 Delims==”%%H in('Set$Ref[^ |%\uuuu APPDIR\uuuuu%findstr.exe/c:%%G“)执行(
对于/F“Tokens=2 Delims=。”(%%H)中的%%1执行回显(引用:%%G类型:%%1值:%%I
)
示例输出:

Reference: R14201 type: profile value:15
Reference: R14201 type: home    value:14
Reference: R14201 type: profile value:15
Reference: R14202 type: profile value:12
Reference: R14203 type: profile value:15
Reference: R14203 type: profile value:11
Reference: R14204 type: profile value:12

用(“!myIteratorArray[%%i]!”)中%%j的
替换
echo!myArray[!myIteratorArray[%%i]!]!!
do echo!myArray[%%~j]!
…感谢您的回答,我正在查看!在这项工作中,我将编辑我的原始帖子以显示使用的代码。我成功地创建了所有所需的变量,并设法在它们上循环,以将结果写入文本文件。