我目前有一個批處理文件正在經歷一個文本文件並將每行分配到一個數組中。我想循環遍歷循環,並從數組中的每個值中刪除一定數量的字符。這可能嗎?在批處理文件中操作數組中的字符串?
@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