length of the content of a variable in batch

  • Thread starter Thread starter Jozsef Bekes
  • Start date Start date
J

Jozsef Bekes

Hello All,

is there a way to get the length of the data that is in a variable?
E.g. I have

Set MYVAR1=12 w%#&er"s^

or for a avarialbe defined like this also:
set aaa=1 2
set aaa=%aaa:~1,2%

Is there a method that calculates the length of this variable as 12?

Thank you,
Jozsi
 
Hi Ray

Thank you for your answer. This method does not work for strings that
include one quotation mark, like this:

"asd"asdas"

and for me it would be critical that the string can contain anything. Does
anyone have another solution?

Thank you,
Jozsi
 
It work for me.
set var="asd"asdas"
call varlen var len
@echo %len%

11





Hi Ray

Thank you for your answer. This method does not work for strings that
include one quotation mark, like this:

"asd"asdas"

and for me it would be critical that the string can contain anything. Does
anyone have another solution?

Thank you,
Jozsi


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
Hi,

yes, it was my mistake, I did not exactly copy-paste the code but modified
it a bit and included an error. Thank you very much for your help.

Jozsi

Jerold Schulman said:
It work for me.
set var="asd"asdas"
call varlen var len
@echo %len%

11
 
Back
Top