! in DOS command

Hi, what is the meaning of "!" here?
set x =  100000
set x = !x:0,4!

Open in new window

Is there a link?

Thanks.
zhshqzycAsked:
Who is Participating?
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
When SetLocal EnableDelayedExpansion is on, that acts similar to % as in assigning a variable a value.

See:
http://ss64.com/nt/setlocal.html
0
 
zhshqzycAuthor Commented:
Then what is
x:0,4

Open in new window

0
 
Bill PrewCommented:
To expand a bit further.

set x =  100000

This will set a variable named x with a value of 100000 (as a string).  I should note though that the extra spaces around the = sign will be a problem, and it should be:

set x=100000

Okay, then this line:

set x = !x:0,4!

will get the current value of x (that the right side reference to !x! and also use substring capability in the SET command (see SET /? at a command prompt for more info) to return only the left 4 characters.  The 0 says start at the left most character (it's relative to 0), and the 4 is the number of characters to get.  This is like a Mid() or Substr() in some other languages.

so this command will get the left 4 characters of the current value in x, and assign it to x.  Same isse with spaces around the = sign as above, so it needs to be:

set x=!x:0,4!

~bp
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
zhshqzycAuthor Commented:
Okay. It's a dos substring manipulation. Why I can't found it in microsoft web site?
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Probably because Microsoft is HUGE and has hundreds if not thousands of different programming teams and web hosting teams and other teams... coordinating where everything is a MONSTER task and things get lost and / or buried.  That's in part why Google is your friend.
0
 
zhshqzycAuthor Commented:
Okay. Thank you very much. Points are given. If you find it in offical miscrosoft web, just please post it. :)

0
 
Bill PrewCommented:
Not a Microsoft write up (I couldn't find the substring part of the SET there easily), but a great reference:

http://www.robvanderwoude.com/ntset.php

~bp
0
 
Steve KnightIT ConsultancyCommented:
well you will find this sort of stuff it in the help of

set /?
For /?
Setlocal /?
Etc.

Which are actually quite good.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.