我目前有一个批处理文件正在经历一个文本文件并将每行分配到一个数组中。我想循环遍历循环,并从数组中的每个值中删除一定数量的字符。这可能吗?在批处理文件中操作数组中的字符串?
@ECHO off
findstr /C:"number" /C:"type" testFile.txt > oneresult.txt
set "file=oneresult.txt"
set /A i=0
timeout /t 1
echo ---------------Results--------------- > results.txt
for /f "tokens=*" %%x in (oneresult.txt) do (
call echo %%x >> results.txt
call set array[%i%]=%%x
set /A i+=1
)
call echo %i% files received >> results.txt
del "oneresult.txt"
所以现在它只是从testFile.txt打印检索到的字符串,然后它们最终放置到result.txt中。我希望所有来自testFile.txt的字符串都有前10个字符。如果有更简单的方法,请让我知道。到目前为止,这是我发现的,但我也是一个批次noob。
就想通了,而不阵列和发布其他人可能会在未来寻找答案:
@ECHO off
findstr /C:"number" /C:"type" testFile.txt > oneresult.txt
set /A i=0
timeout /t 1
echo ---------------Results--------------- > results.txt
for /f "tokens=*" %%x in (oneresult.txt) do (
setlocal enabledelayedexpansion
call set print=%%x
call set newprint=!print:~32!
call echo !newprint! >>results.txt
endlocal
set /A i+=1
)
call echo %i% files received >> results.txt
del "oneresult.txt"
所有阵列管理批处理文件的详细信息解释在[这个答案](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990)。例如:'set array [!i!] = %% x' and'for %% i in(!i!)do echo!array [%% i]:〜32!' – Aacini