Re chenhui530:
你我的方法应该都忽略了连接名中存在空格和冒号的情形,根据你的代码略作修改。
有趣的是,据此发现 ipconfig 的命令输出中,每行文本的结尾都是两个回车符(0x0D)和一个换行符(0x0A),所以在最初使用 delims=2* 测试时,出现了一系列有趣的设置混乱,比如我可以用它实现隐藏环境变量名的首字符。不过后来记起在论坛中已经有 无奈何 兄首先发现了这个现象,链接如下:
(已结)請問如何抓取文件中的某一行特定文字
http://www.cn-dos.net/forum/viewthread.php?tid=17443#pid102925
不知这是程序的BUG,还是在某些特殊应用中的特殊需求。不过它确实给我们在批处理中的使用带来了一些小麻烦。
@echo off
for /f "skip=3 tokens=2*" %%a in ('ipconfig') do set AccessName=%%b&& goto AccName2
:AccName2
set AccessName=%AccessName:~0,-2%
echo Access: "%AccessName%"
Last edited by willsort on 2005-11-15 at 16:29 ]
Re chenhui530:
The methods of you and I should both have ignored the situations where there are spaces and colons in the connection name. I made a slight modification based on your code.
Interestingly, it was found that in the command output of ipconfig, the end of each line of text is two carriage returns (0x0D) and one newline (0x0A). So when I initially tested with delims=2*, a series of interesting setting confusions occurred, such as I could use it to hide the first character of the environment variable name. But later I remembered that Brother Wu Nai He first discovered this phenomenon in the forum, and the link is as follows:
(Solved) Please ask how to capture a specific line of text in a file
http://www.cn-dos.net/forum/viewthread.php?tid=17443#pid102925
I don't know if this is a bug in the program or a special requirement in some special applications. But it does bring some small troubles to our use in batch processing.
@echo off
for /f "skip=3 tokens=2*" %%a in ('ipconfig') do set AccessName=%%b&& goto AccName2
:AccName2
set AccessName=%AccessName:~0,-2%
echo Access: "%AccessName%"
Last edited by willsort on 2005-11-15 at 16:29 ]