1.

Solve : batch read character from text..?

Answer»

hi
first sorry for my bad english...

how can i read character from text file with batch,
SOMETHING like this:

:TEXT (example of my text)
hello my
name is

i want read this character for me, like this:
set/p cha=""
if %cha%==2 [then show me second word, like "e" character of hello in first line,
and "9" show me only "n"...]

tnx

I created a hello.txt file with the two lines you posted and used it as input. The script converts the two lines of hello.txt into a single data stream. This allows character 9 to resolve to 'n'.

hello.txt
Code: [Select]hello my
name is

Code: [Select]@echo off
setlocal enabledelayedexpansion

for /F "tokens=*" %%a in ('findstr /R ".*" hello.txt') do (
set "line=%%a"
set longLine=!longline!!line!
)

set /p chr=Enter Character Position:
set /a chr-=1
call set "shortChar=%%longLine:~!chr!,1%%"

echo %shortChar%

Quote from: behzad-007 on February 17, 2013, 05:16:00 AM

hello my
name is

Some characters will cause problems if your text is more than ALPHANUMERIC. In that case you will need some extra code. Just sayin'Quote from: Sidewinder on February 17, 2013, 11:36:18 AM
I created a hello.txt file with the two lines you posted and used it as input. The script converts the two lines of hello.txt into a single data stream. This allows character 9 to resolve to 'n'.

hello.txt
Code: [Select]hello my
name is

Code: [Select]@echo off
setlocal enabledelayedexpansion

for /F "tokens=*" %%a in ('findstr /r ".*" hello.txt') do (
set "line=%%a"
set longLine=!longline!!line!
)

set /p chr=Enter Character Position:
set /a chr-=1
call set "shortChar=%%longLine:~!chr!,1%%"

echo %shortChar%



it's WORK!
tnx


Discussion

No Comment Found