how to read each character from a text file.?

November 1, 2011 at 05:16:39
Specs: Windows 7, 2.66 GHZ
how to write a "for" loop program to read each character or number in a .txt file and display in BATCH PROGRAMMING...........???

See More: how to read each character from a text file.?

Report •


#1
November 1, 2011 at 18:07:54
How do you want each character/number to be displayed? One character to each line?

Example of input text file please.


Please come back & tell us if your problem is resolved.


Report •

#2
November 5, 2011 at 01:19:14
I want each character to be read in a variable and then i want to use the variable for operation...

for eg:
the txt file contains data "hello"
so i want to read each letter in the word hello using a for loop...
first loop:
%strng%=h
second loop:
%strng%=e

....so,on....


Report •

#3
November 5, 2011 at 18:56:04
Please test this:

@echo off
setlocal enabledelayedexpansion 
cls
set nbr=0

:: Get input line from file
set /p input=<trial.txt

:: Get length of input line
set cnt=0
for /l %%A in (0,1,80) do (
    set chars=!input:~%%1!
    if defined chars set /a cnt+=1
)

:: Create variables containing one character
:loop
    call set char!nbr!=%%input:~!nbr!,1%%
    set /a nbr+=1
    if !nbr! gtr !cnt! (goto finis
    ) else (
    goto loop
)

:: Display variable content
:finis
echo %char0%   %char1%   %char2%   %char3%   %char4%   



Please come back & tell us if your problem is resolved.


Report •
Related Solutions


Ask Question