本帖最后由 aloha20200628 于 2024-5-27 14:42 编辑
回复 1# licunwei
假设一楼测试文件或源文件是utf-8编码,存于 d:\xml\test.xml,则以下代码须用utf-8编码存为test.bat运行,其输出结果文件是 d:\xml\test.txt- @echo off &setlocal enabledelayedexpansion &chcp 65001>nul
- for %%c in ("CPCIssueOrg:车站名称", "EnTime:时间", "CPUVlp:IC卡车牌", "EnVLP:入口车牌", "OBUVlp:OBU车牌", "VLP:出口车牌") do for /f "tokens=1-2 delims=:" %%1 in ("%%~c") do (set "%%~1=%%~2")
- (for /f "usebackq skip=9 delims=" %%a in ("d:\xml\test.xml") do (
- set "s=%%a"&for %%k in ("CPCIssueOrg", "EnTime", "CPUVlp", "EnVLP", "OBUVlp", "VLP") do (
- set "v=!s:*%%k=!"&for /f tokens^=^1^delims^=^" %%b in ("!v:~2,25!") do echo,!%%~k!:%%b
- )
- chcp 936>nul&endlocal&exit/b
- ))>"d:\xml\test.txt"
复制代码 假设一楼测试文件或源文件是ansi编码,存于 d:\xml\test.xml,则以下代码须用ansi编码存为test.bat运行,其输出结果文件是 d:\xml\test.txt
- @echo off &setlocal enabledelayedexpansion
- for %%c in ("CPCIssueOrg:车站名称", "EnTime:时间", "CPUVlp:IC卡车牌", "EnVLP:入口车牌", "OBUVlp:OBU车牌", "VLP:出口车牌") do for /f "tokens=1-2 delims=:" %%1 in ("%%~c") do (set "%%~1=%%~2")
- (for /f "usebackq skip=9 delims=" %%a in ("d:\xml\test.xml") do (
- set "s=%%a"&for %%k in ("CPCIssueOrg", "EnTime", "CPUVlp", "EnVLP", "OBUVlp", "VLP") do (
- set "v=!s:*%%k=!"&for /f tokens^=^1^delims^=^" %%b in ("!v:~2,25!") do echo,!%%~k!:%%b
- )
- endlocal&exit/b
- ))>"d:\xml\test.txt"
复制代码
|