Re: Re: String Indexing

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jerold Schulman (Jerry_at_jsiinc.com)
Date: 04/01/04


Date: Thu, 01 Apr 2004 09:26:54 -0500


See tip 4860 in the 'Tips & Tricks' at http://www.jsiinc.com

I guess if it no label is specified it simply parses the strings and runs the
command.

On Thu, 1 Apr 2004 04:23:39 -0800, "Brown Delivers"
<anonymous@discussions.microsoft.com> wrote:

>Thanks Phil.
>
>The first version (for 2000 and above) makes sense to me
>but I'm curious as to how version two (for NT and above)
>works.
>
>If the line
>
>call Set Progress=%%Total:~0,%X%%%
>
>is replaced with
>
>call :Set Progress=%%Total:~0,%X%%%
>
>the shell complains "The system cannot find the batch
>label specified - Set". This makes sense since their is
>no label explicitly defined as Set. However, why or how
>does it work without the colon?
>
>>-----Original Message-----
>>Brown Delivers wrote:
>>> Can a varible not be used to indicate the "length" when
>>> string indexing? This is what I observe:
>>>
>>> Set Total=********************
>>> Set X=10
>>> Set Progress=%Total:~0,10%
>>>
>>> C:\>ECHO %Progress%
>>> **********
>>>
>>> Now, say I try to use variable X to indicate the length:
>>>
>>> Set Progress=%Total:~0,%X%%
>>>
>>> C:\>ECHO %Progress%
>>> X%%
>>>
>>> What am I doing wrong?
>>
>>The first version below is for Win2000 or newer versions
>of NT:
>>
>><Win2000> c:\cmd>demo\StrIndex
>>Progress=**********
>>
>><Win2000> c:\cmd>rlist demo\StrIndex.cmd
>>=====begin c:\cmd\demo\StrIndex.cmd ====================
>>1. @echo off
>>2. setlocal enabledelayedexpansion
>>3. Set Total=********************
>>4. Set X=10
>>5. Set Progress=!Total:~0,%X%!
>>6. Set Progress
>>=====end c:\cmd\demo\StrIndex.cmd ====================
>>
>>The following version is for NT 4.0 (but will work in any
>version
>>of NT):
>>
>><Win2000> c:\cmd>demo\StrIndexNT40
>>Progress=**********
>>
>><Win2000> c:\cmd>rlist demo\StrIndexNT40.cmd
>>=====begin c:\cmd\demo\StrIndexNT40.cmd
>====================
>>1. @echo off
>>2. setlocal
>>3. Set Total=********************
>>4. Set X=10
>>5. call Set Progress=%%Total:~0,%X%%%
>>6. Set Progress
>>=====end c:\cmd\demo\StrIndexNT40.cmd
>====================
>>
>>--
>>Phil Robyn
>>Univ. of California, Berkeley
>>
>>u n z i p m y a d d r e s s t o s e n d e - m a
>i l
>>.
>>

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



Relevant Pages

  • Re: String Indexing
    ... @echo off ... Set Progress ... >Phil Robyn ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: String Indexing
    ... This is what I observe: ... @echo off ... Set Progress ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Obtain drive letter assignment of CD/DVD drive?
    ... the Line references were not recognized ... You defined %Label% yourself in the second line! ... your version of the batch file as an attachment to your ... echo No %Label% found ...
    (microsoft.public.windowsxp.general)
  • Re: Set Day of week problems...
    ... > must NOT have a cr-lf at the end. ... > ECHO .| copy dircmd.txt temp.bat ... I called my batch file T.BAT and here's how it ... > Volume in drive H has no label. ...
    (comp.programming)
  • Re: kernel panic
    ... You should be able to apply a label to whatever swap partition you have on this machine with 'mkswap -L ...'. ... insmod /lib/scsi_mod.o echo "Loading sd_mod module" ...
    (Fedora)