在cmd中重新排列数组元素 [英] Rearrange array elements in cmd

查看:82
本文介绍了在cmd中重新排列数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的批处理文件中有一个数组,如下所示:

I have an array in my batch file which looks like this:

"port[0] ="
"port[1] = 0"
"port[2] = 3"
"port[3] = 2"

是否有任何精美而优雅的方法将值移回一个元素,因此看起来像这样?

Is there any nice and elegant way to move values one element back, so it'll look like this?:

"port[0] = 0"
"port[1] = 3"
"port[2] = 2"
"port[3] ="

我想要的内容不只是 SET port [0] =% port [1]%,等等?

I want something other than just SET port[0] = %port[1]%, etc?

推荐答案

:: Q:\Test\2018\11\23\SO_53453204.cmd
@Echo off&SetLocal  EnableDelayedExpansion
set "port[0]="   &Rem this clears/deletes the variable
set "port[1]=0"
set "port[2]=3"
set "port[3]=2"

For /L %%L in (1,1,3) do (
  set /A "New=%%L-1,Last=%%L"
  set "port[!New!]=!port[%%L]!"
)
:: finally reset the last entry
set "port[%Last%]="
set port[







> Q:\Test\2018\11\23\SO_53453204.cmd
port[0]=0
port[1]=3
port[2]=2

这篇关于在cmd中重新排列数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆