- Aug
- 2,199
- 98
Code:
:: This batch file allows you to paste in whatever text that you want,
:: into the batch file,
:: and then place each line of text into an array element.
::
:: This eliminates the need to read text in from a separate file.
::
:: This does not take into account expansion and special characters in the text,
:: such as what might be found in URL addresses.
::
:: RULES:
:: 1) The batch label containing the data must be :the_data
:: 2) The batch label :the_data must be the last label in the batch file
:: 3) Your text must be placed between the :the_data label and the return
::
:: TCC 11.00.50 Windows XP [Version 5.1.2600]
:: TCC Build 50 Windows XP Build 2600 Service Pack 3
@setlocal
@echo off
gosub get_data
::
:: Do whatever you want with the data
:: I am going to display it
::
do i = 1 to %lc
echo %aData[%i]
enddo
echo.
echo Total Data Items: %lc
::
:: Data elements begin at 1
:: Total number of data elements is stored in %lc
:: The array is called aData
::
:: Remove the array
::
unsetarray aData
endlocal
quit
:get_data
:: Find out where the last label :the_data is in this batch file
::
ffind /klmrt":the_data" "%_batchname" > clip:
::
:: Get rid of everything but the line number
::
set the_data=%@filter[0123456789,%@clip[0]]
::
:: Save the line where the data begins
::
set data_line=%the_data
::
:: Find out how many lines of data there are
::
set lc=0
do forever
if %@line["%_batchname", %data_line] eq return leave
set lc=%@inc[%lc]
set data_line=%@inc[%data_line]
enddo
::
:: Create an array for the data items
::
setarray aData[%@eval[%lc+1]]
::
:: Read the data into the array
:: Arrays begin at 0. I'm starting at 1
::
do i = 1 to %lc
set aData[%i] = %@line["%_batchname", %@eval[%the_data + %i - 1]]
enddo
return
:the_data
This is line 1
This is line 2
This is line 3
This is line 4
return