Set Command Special usage _dos/bat

Source: Internet
Author: User
1, the use of set/a to remove the date before the number 0, such as: 2007-09-25 in the month of 09 before the 0 (of course, this month is unknown, simple to say

Yes no matter whether there are 0 to be guaranteed to remove the front:
Demo Code:

Copy Code code as follows:

@echo off
Set day=1%date:~5,2%
set/a day-=100
Echo%day%
Pause>nul

In addition, you can (in depth use, more advantages than the previous one):

Copy Code code as follows:

@echo off
set/a day1=%date:~5,1%,day2=%date:~6,1%
set/a day=%day1%*10+%day2%
Echo%day%
Pause>nul


2, the use of set/a (numerical operation division in the divisor does not allow 0) return value to set the numerical operation of the carry flag;
Demo Code:

@echo off 2>nul 3>nul
set/a num1=7,num2=2
set/a var=%num1%+%num2%
SET/A 1/(%VAR%/10) && echo greater than 10 | | Echo is less than 10
Pause>nul
Plus a large number of addition operations demo code: (first complement)

Copy Code code as follows:

@echo off&setlocal enabledelayedexpansion
Set num1= 984322212445613542523552165432136516565135132354123432987619431469731611346143789
Set num2= 657973265856194306419643120641631361303163006131061301613061130161300613061130
Call:lineup num1
Call: Lineup num2
set/a flag=0
for/l%%i in (1 1 199) do (
set/a var=!num1:~-%%i,1!+!num2:~-%%i,1!+!flag!
Set var=0!var!
Set flag=!var:~-2,1!
Set str=!var:~-1!! Str!
)
for/f "Delims=0 tokens=*"%%i in ("!str!") doing echo%%i
Pause>nul

: Lineup obj
for/ L%%i in (1 1) do set%1=0!%1!
Call Set%1=!%1:~-200!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.