Reputation:
What I'm aiming for is to assign strings,each from a different line(from a txt file),to each its own variable.
example of the txt:
1
2
3
I tried doing it by assigning type
output of the txt file on a variable with the for command
FOR /F "delims=" %%i IN ('type "textfile.txt"') DO set testingVariable=%%i
%testingVariable% being the variable,I then tried string manipulation like this
set newVariable=%testingVariable:~3,1%
hoping it would come out as 2
, the only results I had were either 0 on all 3 numbers or just nothing.
Is there a simple a simple solution to this?
(and if possible try to explain as much as you can as i am still somewhat of a beginner)
Upvotes: 1
Views: 75
Reputation: 56180
You want every line into a seperate variable? You need a counter:
setlocal enabledelayedexpansion
set c=0
FOR /F "delims=" %%i IN ('type "textfile.txt"') DO (
set /a c+=1
set testingVariable[!c!]=%%i
)
set testingvariable[
... and you need delayed expansion
Note: emty lines are skipped
Upvotes: 1