Page 1 of 1

Determine Integer

Posted: 15 Jun 2011 01:38
by Cleptography
How can I search through a text file like this and determine the integers?

Code: Select all

99201 22839 19283
19283 ABSJD 92839
00293 LSKDJ 90LSK

Re: Determine Integer

Posted: 15 Jun 2011 01:45
by nitt
Cleptography wrote:How can I search through a text file like this and determine the integers?

Code: Select all

99201 22839 19283
19283 ABSJD 92839
00293 LSKDJ 90LSK


I do not understand what you mean by "determine". Do you want to like run a FOR loop through every character and if one is an integer then return true for that one loop or something? Or do you want to check an entire line, or the entire thing? Or do you want to count how many integers there are?

Re: Determine Integer

Posted: 15 Jun 2011 01:57
by Cleptography
Just check each group of chars and determine if it is an integer, and if it is not print something that says ????? was not an integer.
This might make it easier.

Code: Select all

02932
10293
KL039
12OPE
93029


So determine which of the above are integers.
Thanks nitt

Re: Determine Integer

Posted: 15 Jun 2011 03:41
by orange_batch
Easy as pie. 8)

Code: Select all

for /f "tokens=1" %%a in (textfile.txt) do set var=&set /a var+=1%%a 2>nul||echo:%%a is not an integer.

We prefix the 1 to prevent DOS from interpreting a number starting with 0 as an octal. It also prevents set /a from interpreting any %%a starting with a letter as a variable.

Re: Determine Integer

Posted: 15 Jun 2011 04:23
by Cleptography
Good job orange :mrgreen:

Code: Select all

for /f "Tokens=*" %%a in ('type %1') do (
   if %%a NEQ +%%a echo\Line containing {%%a} in file %1 is NOT an integer.
)