Trying to extract characters from a string va

May 13, 2009 at 09:06:35
Specs: Windows XP
The program I am writing will ultimately FIND occurrences of predetermined strings from a text file (in this case the output of systeminfo)

I can extract the needed lines with this code (which works)

ECHO Outputting System Info
systeminfo >>tempsys.txt
set tempsys=tempsys.txt
set /a count=1
set outputarray=Host Name/OS Version/Registered Owner/System Manufacturer/System Model/SYstem type/Total Physical Memory/Domain
:TESTMORE
FOR /F "tokens=%count% delims=/" %%G IN ("%outputarray%") DO type %tempsys% | find /i "%%G" >>%OUTPUT%
IF %count%==8 GOTO :TESTEXIT
set /a count=%count%+1
GOTO :TESTMORE
:TESTEXIT
del tempsys.txt

What has me bugged is that I must declare the number of delimiters in the outputarray variable in the line

IF %count%==8 GOTO :TESTEXIT

What I want to do is write a bit of code to count the number of delimiters in the outputarray variable... I have found this is not so easy... here is what I have come up with:

:TEST
SET /a _dummy=0
SET _length=1
SET _donor=Host Name/OS Version/Registered Owner/System Manufacturer/System Model/SYstem type/Total Physical Memory/Domain;
SET /a count=0
SET delimchar=/
:evenmoretesting
SET substring=!_donor:~%_dummy%,1!
echo %substring%
IF substring1==delimchar CALL :gotone
SET /a _dummy=%_dummy%+1
IF %_dummy% ==60 exit /b
goto :evenmoretesting
:OUT
echo (%count%)
exit /b
:gotone
echo got one

This is a bit of testing code and what it does do correct is extract each character from the _donor variable but when I compare substring to delimchar it never hits as TRUE. Am I just whistling into the wind and I am stuck manually putting in the counter variable or can a programmatic solution be found?

BTW: if I ever can successfully make the comparison I will just add a variable endchar to test for the end of the _donor variable.


See More: Trying to extract characters from a string va

Report •


#1
May 13, 2009 at 15:01:29
Here's a way to count tokens.

============================
@echo off & setLocal EnableDelayedExpansion

set str=Host Name/OS Version/Registered Owner/System Manufacturer/System Model/SYstem type/Total Physical Memory/Domain
set /a N=0

:loop
for /f "tokens=1* delims=/" %%a in ("!str!") do (
set /a N+=1
if "%%b" neq "" set str=%%b&& goto :loop
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
May 13, 2009 at 15:22:08
Wonderful! Thanks for the quick reply and even quicker code!

Report •

Related Solutions


Ask Question