Page 1 of 1

Substring

Posted: 31 May 2011 01:26
by santhosh
Dear Orange/agerman,

i have a doubt is it possible to separate a string in substring in DOS(input file are in .txt format),example
input:-
2323,344429890
41234,454324424252
41241,35433353535
output:-
have to print only first 4 number in second column
3444
4543
3543
Thanks in advance

Re: Substring

Posted: 31 May 2011 01:37
by orange_batch
Oh, being singled out? That's a first. 8)

If you want to store these numbers all in variables it would be different, but to do exactly as you said is also very easy.

Without delayed expansion:

Code: Select all

for /f "delims=, tokens=2" %%a in (input.txt) do (
set tempvar=%%a
call echo:%%tempvar:~,4%%
)

With delayed expansion:

Code: Select all

setlocal enabledelayedexpansion
for /f "delims=, tokens=2" %%a in (input.txt) do (
set tempvar=%%a
set tempvar=!tempvar:~,4!
echo:!tempvar!
)

delims=,
2323,344429890

tokens=2
2323,344429890

tempvar:~,4 (same as tempvar:~0,4)
2323,344429890