B
Barney
How can I determine the number of characters in an
environment variable (%ComputerName%)?
environment variable (%ComputerName%)?
Barney said:How can I determine the number of characters in an
environment variable (%ComputerName%)?
Matthias Tacke said:Hello Barney, one way is to append a char unlikely to occur in the var
to a copy, strip 1st char until your marker found:
set cnt=1
set chk=%computername%¬
:loop
set chk=%chk:~1%
if not "%chk%"=="¬" Set /A cnt+=1 & goto :loop
echo/Computername: %computername% length:%cnt%
HTH
Hello Barney, one way is to append a char unlikely to occur in the var
to a copy, strip 1st char until your marker found:
set cnt=1
set chk=%computername%¬
:loop
set chk=%chk:~1%
if not "%chk%"=="¬" Set /A cnt+=1 & goto :loop
echo/Computername: %computername% length:%cnt%
HTH
How can I determine the number of characters in an
environment variable (%ComputerName%)?
I know, never post before testing, but did it myself. The expressionMatthias Tacke said:Oops,
in the unlikely case of an empty computername or for general use, this
is correct:
set cnt=0
set chk=%computername%¬
:loop
if not "%chk%"=="¬" Set /A cnt+=1 & set chk=%chk:~1% & goto :loop
echo/Computername: %computername% length:%cnt%
-----Original Message-----
No need to append a character, though it needs an added call.
@echo off
set computername=12345678
set cnt=0
:loop
call set chk=%%computername:~%cnt%,1%%
if defined chk Set /A cnt+=1 & goto :loop
echo/Computername: %computername% length:%cnt%
.
Barney said:How can I determine the number of characters in an
environment variable (%ComputerName%)?