在命令提示符下,执行 help set . 在那里,您将找到有关 set 命令的更多信息,而不是您想知道的 . 你感兴趣的部分说:
May also specify substrings for an expansion.
%PATH:~10,5%
would expand the PATH environment variable, and then use only the 5
characters that begin at the 11th (offset 10) character of the expanded
result. If the length is not specified, then it defaults to the
remainder of the variable value. If either number (offset or length) is
negative, then the number used is the length of the environment variable
value added to the offset or length specified.
当然,为了将这种东西与 for 循环变量一起使用,您需要首先了解在Windows NT批处理文件中扩展变量的非常特殊的方式 . 如果您遇到问题,请告诉我,我可以添加更多信息 .
2
设置 HELP SET 并尝试以下操作来帮助您入门
@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (sample.txt) do (
set line=%%a
set chars=!line:~0,5!
echo !chars! --- !line!
)
2 回答
在命令提示符下,执行
help set
. 在那里,您将找到有关set
命令的更多信息,而不是您想知道的 . 你感兴趣的部分说:当然,为了将这种东西与
for
循环变量一起使用,您需要首先了解在Windows NT批处理文件中扩展变量的非常特殊的方式 . 如果您遇到问题,请告诉我,我可以添加更多信息 .设置
HELP SET
并尝试以下操作来帮助您入门