批处理文件数组的创建/修改 [英] Batch file Array creation/modification

查看:60
本文介绍了批处理文件数组的创建/修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试使用批处理来创建数组,我知道这是原始的,但是我正在从头开始学习代码,所以批处理是我非常想学习的东西,无论如何我还是要跳到其他东西,我知道我可以使用以下语法创建数组:

so i am trying to make an array using batch, i know, primitive, but i'm learning code from the ground up, so batch is something i'd love very much to learn before i jump to something else, anyways, i know i can create an array using this syntax:

@echo off set a[0] = 1 set a[1] = 2 set a[2] = 3 set a[3] = my input variable here

@echo off set a[0] = 1 set a[1] = 2 set a[2] = 3 set a[3] = my input variable here

我的问题是,如何使用用户输入向阵列添加新行或修改现有行?

My question is, how can i add a new line to the array or modify an existing one using user input ?

我的意思是我想将用户输入变量用作新行或修改数组上的现有行!

I mean that i'd like to use a user input variable as a new line or modify an existing line on the array !

推荐答案

所以我在DOS论坛上找到了我需要的东西,这很简单:

so i found what i needed on a DOS forum, it was pretty simple:

< myfile.txt ( set /p line1= set /p line2= set /p line3= set /p line4= set /p line5= ) set line

< myfile.txt ( set /p line1= set /p line2= set /p line3= set /p line4= set /p line5= ) set line

我仍然想修改一些东西,例如添加自动的行数增量,因此每次将新字符串添加到文本文件时,它都会自动创建一个新的字符串(设置/p line"n" =),所以现在它可以满足我的需要,它可以读取指定文本文件中的每一行,并将其放置在列表中的变量上,一旦存在,我就可以将变量用于所需的对象,而不必是一个数组,但可以足够接近,唯一的事情是,如果您未实现自动行增量",则必须手动创建空变量,就像我在上面的代码示例中所做的那样,您可以看到我最多写了"5个变量",因此如果输入第6个,仍会将其添加到文本文件中,但脚本不会列出它,因此需要自动增加空变量.

i still want to modify some things, like adding automatic line count increment, so every time a new string is added to the text file, it will automatically create a new (set /p line"n"=) so right now it works for what i want, it reads each line on the specified text file, and places it on a variable on the list, once is there, i can use the variable for whatever i need, not exactly an array, but close enough, only thing, if you do not implement "automatic line increment" you have to manually create the empty variable, as i did on the code example above, you can see i wrote up to "5 variables" so if you enter a 6th, it will still add it to the text file, but the script won't list it, therefore, the need to automatically increment the empty variables.

这篇关于批处理文件数组的创建/修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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