Do /L again

#1
Hello.

My issue:

I'm parsing string using Do /L with delimiter /T

Code:
*Do item in /T";" /L .COM;.EXE;.BAT;.CMD
   *Echo ^>%[item]^<
*EndDo
Works, as expected.

Now I want to add at the first position an empty item:
Code:
*Do item in /T";" /L ;.COM;.EXE;.BAT;.CMD
   *Echo ^>%[item]^<
*EndDo
Works as previous code, unexpected

But it is possible to add an empty item at the end. This example works as expected:
Code:
*Do item in /T";" /L .COM;.EXE;.BAT;.CMD;
   *Echo ^>%[item]^<
*EndDo
Any suggestions?
 
May 29, 2008
533
3
Groton, CT
#2
This won't work in general, but if you're processing file extension strings, try using just a "." as the first item like
Code:
*Do item in /T";" /L  .;.COM;.EXE;.BAT;.CMD
 
#5
Wow.
Code:
do i in /T";" /L ^k^k;a;b;c; ( echo **%i** )
Magic :) Please explain - I have no idea.
^k is an escape sequence for the backquote. If you put a literal `` there, it would disappear too soon. The escape sequence delays that. That's the best I can do. Others seem to understand TCC's parsing better than I do.
 
#6
Something to think about:
Code:
v:\> echo ``


v:\> echo ^k^k
``

v:\> echo %@execstr[echo ^k^k]


v:\> echo %@execstr[echo ^^k^^k]
``

v:\> echo %@execstr[echo ^^^k^^^k]
``
 
Last edited:
#8
Hmm... Looks OK, but... in
Code:
do i in /T";" /L ^k^k;a;b;c ( echo %i )
The result is
Code:
a
b
c
I would expect to get
Code:
ECHO OFF
a
b
c
Unescaped ^k^k is discarded by echo, but it is not an empty string:
Code:
do i in /T";" /L ^k^k;a;b;c ( echo %@len[%i] )
do i in /T";" /L ^k^k;a;b;c ( echo %@quote[%i] )
May be, solution of my issue doesn't exist :( I've decided to add some logic to my script.