Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: how to save a text file into an array  (Read 2907 times)

0 Members and 1 Guest are viewing this topic.

scomp

    Topic Starter


    Rookie

    how to save a text file into an array
    « on: June 17, 2008, 11:51:06 AM »
    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 advance

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: how to save a text file into an array
    « Reply #1 on: June 17, 2008, 12:16:19 PM »
    Code: [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 8)
    « Last Edit: June 17, 2008, 02:55:25 PM by Sidewinder »
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    scomp

      Topic Starter


      Rookie

      Re: how to save a text file into an array
      « Reply #2 on: June 18, 2008, 02:00:03 AM »
      thanks sidewinder

      Spasm



        Greenhorn

        Re: how to save a text file into an array
        « Reply #3 on: June 18, 2008, 04:23:54 AM »
        Yeah, what language are you programming in?