Solved How can i access more than 31 tokens in FOR loop?

October 9, 2015 at 10:26:29
Specs: Windows 8
An application I'm using outputs binary output to a temp file like so:
I need sets of 5, in order, so I would like to get
My attempt was to make a for loop, with delim being "-" and tokens being !A!-!B!. 'A' would be first set to 1. 'B' to 5, after the tokens were set to a variable, 5 was added to them, simple 'A'-'B' got to 31, in which case they set themselfes as the FOR parameters.

Is there a way to get sets of 5 tokens past 31, or a better way of tackling this in general?

message edited by Arescet

See More: How can i access more than 31 tokens in FOR loop?

Report •

October 9, 2015 at 10:55:07
The for segment command is:
(delayed expansion is on)

:: Initial token set.

set A=1
set B=5

        for /f "tokens=%A%-%B% delims=-" %%G in (%fileName%) do (
    set val1=%%G%%H%%I%%J%%K

:: Eliminate spaces between variables.
    set val1=%val1: =% 

:: Set token set for next Iteration.
    set /a A=%A%+5
    set /a B=%B%+5
goto :loop

Report •

October 9, 2015 at 17:34:13
✔ Best Answer
I would just ignore/remove the dashes, since they don't do anything. (ie: you have fixed-length fields of one byte, so why delimit?) Then just take bites of 5, then jump forward 5 bites in your variable
::---- begin batch
@echo off & setlocal
for /f "tokens=*" %%a in (file) do (
call :xx %%a
goto :eof

set t=%1
:: remove all the dashes
set t=%t:-=%
:: get first five bites of %t%
set five=%t:~0,5
:: set t to exclude the initial 5 bites just processed
set t=%t:~5%
:: not sure what or what format you want for output. This is just a "place-holder"...
>>z echo %five%
if defined t goto :loop
goto :eof
::------ end batch - not tested

Report •

October 13, 2015 at 07:04:09
Thank you ever so much. Took very little editing to fit it to my needs, and :: notes were ever so useful.

Sidenote: line 17 was missing a % at the end.

message edited by Arescet

Report •
Related Solutions

Ask Question