本帖最后由 neorobin 于 2014-10-17 17:29 编辑
回复 40# terse
有一个问题, 分号 : 不能处理
我做了以下测试 (WinXP 32bit 简体中文版 和 Win7 64bit 简体中文版) | @echo off | | echo 1 & for /f "delims=" %%a in (";") do echo %%a | | echo 2 & for /f "delims=" %%a in (";.") do echo %%a | | echo 3 & for /f "delims=" %%a in (".;") do echo %%a | | echo 4 & for /f "delims=" %%a in (".;.") do echo %%a | | pauseCOPY |
得到输出为
我认为是 for /f 把分号 ; 当成了默认的行注释符(以此字符在行首, 将略过一行)
微软官方文档 eol 字符的解释, 我不认同
eol=c Specifies an end of line character (just one character).
http://technet.microsoft.com/en-us/library/bb490909.aspx
但是这里的描述与事实是相符的
for /F "eol=; tokens=2,3* delims=," %i in (myfile.txt) do @echo %i %j %k
This command parses each line in Myfile.txt, ignoring lines that begin with a semicolon and passing the second and third token from each line to the FOR body (tokens are delimited by commas or spaces).
我尝试用 0x20--0x7E 范围之外的字符来做这个默认的 eol 字符, 比如 0x08, 0x20--0x7E 范围内字符便都可正常获取了, 测试代码如下: | @echo off & mode 80,300 | | | | set "ASCII_20_7E= !"#$%%^&'()*+,-./0123456789:;^<=^>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^^_`abcdefghijklmnopqrstuvwxyz{^|}~" | | set ASCII_20_7E | | | | setlocal enabledelayedexpansion | | | | set /a cnt=0x20 | | for /l %%i in (0x20 1 0x7e) do ( | | for /f "eol=delims=" %%j in ("!ASCII_20_7E:~%%i,1!") do ( | | if "%%j"=="!" echo ASCII-33 | | if "%%j"=="^" echo ASCII-94 | | echo !cnt! [%%j] | | set /a cnt+=1 | | ) | | ) | | pauseCOPY |
|