I am writing one batch script in windows. I want to extract Month part from string 1/12/18
in format m/dd/yy
. Here it is 1 Please help on this.
我在Windows中编写一个批处理脚本。我想从格式为m / dd / yy的字符串1/12/18中提取月份部分。这是1请帮忙。
2/04/17 > 2
5/06/12 > 5
1 个解决方案
#1
1
to split a string, use a for /f
loop:
要拆分字符串,请使用for / f循环:
set "string=2/04/17"
for /f "tokens=1 delims=/" %%a in ("%string%") do set month=%%a
echo %month%
(Note: tokens=2
will be Day, tokens=3
will be Year
)
(注意:令牌= 2将是Day,令牌= 3将是年份)
#1
1
to split a string, use a for /f
loop:
要拆分字符串,请使用for / f循环:
set "string=2/04/17"
for /f "tokens=1 delims=/" %%a in ("%string%") do set month=%%a
echo %month%
(Note: tokens=2
will be Day, tokens=3
will be Year
)
(注意:令牌= 2将是Day,令牌= 3将是年份)