中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-01 11:18
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 求助一个判断空行跳出循环的问题 查看 1,761 回复 1
楼 主 求助一个判断空行跳出循环的问题 发表于 2011-01-23 16:06 ·  中国 上海 虹口区 电信
新手上路
积分 1
发帖 1
注册 2011-01-20 01:17
15年会员
UID 180806
性别 男
状态 离线
有一个注册表文件,我想把它其中的某段提取出来,并生成一个新的注册表,我的思路是先利用循环读取到这一段行号,然后再使用一个循环依次读取该行号以下的每行内容并写入新的注册表文件,遇到第一个空行则跳出循环。但是现在碰到问题,就是如何判断空行,我是这样写的%%b==""&&goto :end,文件是生成成功了,但是CMD窗口老是报错,请教各位大侠如何解决,另请大侠帮我看看代码是否繁琐,是否有更好的写法,万分感谢


以下是注册表样式


"BaseInfoPath"=""
"StkDataPath"=""
"name"="全球指数"
"shortname"="全球"
"labellen"=dword:00000000
"namelen"=dword:00000000
"timezone"=dword:00000008
"opentime1"=dword:00000258
"closetime1"=dword:00000b54
"py"=dword:00000001


"BaseInfoPath"=""
"StkDataPath"=""
"name"="香港联合交易所"
"shortname"="港"
"labellen"=dword:00000000
"namelen"=dword:00000008
"timezone"=dword:00000008
"opentime1"=dword:000003e8
"opentime2"=dword:00000596
"closetime1"=dword:000004ce
"closetime2"=dword:00000640
"py"=dword:00000001


"BaseInfoPath"=""
"StkDataPath"=""
"name"="AH股"
"shortname"="AH"
"labellen"=dword:00000000
"namelen"=dword:00000008
"timezone"=dword:00000008
"opentime1"=dword:000003e8
"opentime2"=dword:00000596
"closetime1"=dword:000004ce
"closetime2"=dword:00000640
"py"=dword:00000001
"mainindex"="HSI"
"Version"=dword:00000064
"TypeMask"="***** 0"
"LargeRepData"=dword:00000001
"LastDynaReq"=dword:00000000
"VarTradeTime"=dword:00000001
"SubType"="AH股 3 1 1"
……………………

以下是我写的代码

@echo off
set Regf=\
for /f "tokens=1* delims=:" %%i in ('type aaa.reg^|findstr /in "%Regf%"') do set /a Regnum=%%i-1
for /f "skip=%Regnum% tokens=1* delims=:" %%a in ('type aaa.reg^|findstr /in .*') do (
echo.%%b >>555.reg
%%b==""&&goto :end)
:end
PAUSE&exit


[ Last edited by wjmcool on 2011-1-23 at 16:08 ]
2 发表于 2011-01-23 16:46 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
积分 1,039
发帖 897
注册 2009-03-01 15:34
17年会员
UID 140302
性别 男
来自 在地狱中仰望天堂
状态 离线
@echo off&setlocal enabledelayedexpansion
(for /f "delims=" %%a in ('type 1.reg') do if defined n (
set "a=%%a"
if "!a:~0,1!!a:~-1!"=="" goto:eof
echo !a!
) else if /i "%%a"=="" set n==&echo %%a
)>1-.reg
或:
@echo off
(for /f "delims=" %%a in ('type 1.reg') do if defined n (
set "a=%%a"
setlocal enabledelayedexpansion
if "!a:~0,1!!a:~-1!"=="" goto:eof
echo !a!
endlocal
) else if /i "%%a"=="" set n==&echo %%a
)>1-.reg


[ Last edited by Hanyeguxing on 2011-1-23 at 17:45 ]
论坛跳转: