1.

Solve : how to save a text file into an array?

Answer»

hi everyone,

I want to know how to save CONTENT of a file into an array.


I want to save a full line into a particular position or address in an array.

e.g.

if a is an array

a(0) = save first line

a(1) = save second line

......

and it should be CONTINUE until all lines are saved.

Can anyone help me?

thank in advanceCode: [Select]@echo off
set IDX=0
setlocal enabledelayedexpansion

for /f "tokens=* delims=" %%x in (test.txt) do (
call set /a idx=%%idx%%+1
call set array.%%idx%%=%%x
)

for /l %%x in (1, 1, %idx%) do (
echo !array.%%x!
)

Batch CODE does not support true arrays although you can mimic one. The first for shows how to load the array from a file. The second for shows the notation NEEDED to access the array elements.

Happy Coding thanks sidewinderYeah, what language are you programming in?



Discussion

No Comment Found