Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Setting array variable ignores leading spaces (and @execarray doesn't)

May
12,834
163
Setting array variable ignores leading spaces. And @execarray[] doesn't. This is a problem. I can't fill an array with @execarray[] copy it to another array expecting the copy to be the same.
Code:
v:\> setarray a[1]

v:\> set a[0]=  xx

v:\> echo **%a[0]**
**xx**

v:\> echo %@execarray[a,echo   xx]
0

v:\> echo **%a[0]**
**  xx**
 
I haven't tried it, but try enclosing your argument in back quotes, i.e., set a[0]= ` xx`
It doesn't work. And even if it did, copying an array would be impossible. In
Code:
set b[%i]=`%a[%i]`
neither %a nor %i on the right hand side would be expanded.

My situation: array a is filled by @EXECARRAY and NETSTAT.EXE. It has leading spaces.
 
I know this doesn't directly address your issue, but you could always assume there are leading spaces and remove them prior to using them - e.g. @TRIM[%a[%i]]
 
I know this doesn't directly address your issue, but you could always assume there are leading spaces and remove them prior to using them - e.g. @TRIM[%a[%i]]
There are many ways to kludge around the problem. Most efficient might be to get rid of them in the first place ...

Code:
@execarray[a,netstat -ano | get_rid_of_leading_spaces]

TPIPE could do that but would be slow compared to, say, SED.
 

Similar threads

Back
Top