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

May 20, 2008
11,546
104
Syracuse, NY, USA
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**
 
May 20, 2008
11,546
104
Syracuse, NY, USA
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.
 

samintz

Scott Mintz
May 20, 2008
1,514
18
Solon, OH, USA
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]]
 
May 20, 2008
11,546
104
Syracuse, NY, USA
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
Thread starter Title Forum Replies Date
vefatica Setting the default value with @REGSET? Support 1
vefatica VIEW ... remember the UTF-8 setting? Support 0
S Setting Tabs=Bottom makes text turn black Support 6
rps TCMD Tabs priority option setting Support 0
R ffind not setting %_ffind_ vars if /f is used Support 7
C How to? Setting up SMTP access for Yahoo with TCMD v20 Support 7
Alpengreis WAD Each start/close of TCMD changes my Explorer setting Support 7
J Variable setting regression in tcc17 ? Support 5
williamleara WAD ribbon doesn't remember expand/collapse setting Support 3
CWBillow Setting and changing Vars in batch files Support 26
Jay Sage SENDMAIL Apparently Not Setting Priority Support 2
G Display setting for Tabbed Toolbar Support 1
D setting days back at prompt Support 12
D Parsing an array variable to an array does not work Support 5
vefatica SET /A and multidimensional array. Support 1
vefatica Array name in a variable? Support 3
J WAD "setarray /f" only overwrites the first array var Support 2
J How to? Array sort according to multiple keys Support 3
S Documentation "DEFINED" vs. array elements Support 1
Frank watch an array variable in ide/bdebugger Support 2
S WAD SET problem - array element initialization Support 11
C Simple .bat question - dump contents of 2 dimensional array Support 2
Charles Dye Array limits Support 8
S How to access array elements? Support 5
S ARRAY enhancements Support 0
vefatica Leading spaces in array variables Support 13
A What is the fastest way to dump a array Support 4
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
P Inserting string into a variable. Support 3
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R Difference between TCC and CMD: variable names with hyphens Support 4
Joe Caverly Get a variable type Support 2
M How to set Path variable for non-executable file extensions in 4DOS Support 8
rps For loop internal %_for_files variable? Support 2
A How to safely print variable's value without quotes? Support 9
nikbackm TCC 20 variable expansion bug Support 6
X How to set %_INIREAD result to variable Support 5
Charles Dye _USBS variable Support 2
BeechComer Debugger: how to set %1 variable? Support 3
Mordachai Variable followed by function constantly failing... Support 5
T Variable indirection for arrays Support 1
Mike Hall Unexpected "Variable loop" in IF condition Support 10
vefatica If there's no PATH variable ... Support 5
C Maximum length for a variable Support 8
D WAD Internal variable _cpu is undefined Support 2
fpefpe How to? Global variable set /v Support 4
I Change value of a variable while debugging Support 3
I "IF" command in a variable does not expand redirection variable name Support 0
Jay Sage WAD Variable _LOGFILE Not Working Support 2
D Fixed Change in behavior of variable expansion between 16 and 17 Support 3

Similar threads