我有一个代码可以通过使用Stephans for循环来获取结果谢谢,但我仍然遇到下面解释的问题
原文:
bbox 7 25 6 04
新文字:
first.one 7
second.two 25
third.three 6
fourth.four 04
下面是我用来尝试用bbox捕获行的代码然后错过它们(就像测试一样)但它总是显示它们如果我可以让它工作我还需要一个代码来返回完整的行(未修改的)如果bbox为false。
@echo off
for /f "tokens=1-20" %%a in (input.txt) do (
echo findstr "bbox" "%%a"
if errorlevel=1 (
echo. >> output.txt
) else (
echo %%a >> output.txt
))
pause
答案 0 :(得分:0)
for /f
循环通常会忽略空行。所以我们必须确定,没有空行(find /n /v "" file.txt
在每行前面加上行号)
其余的很直接:
@echo off
(
for /f "tokens=1,* delims=[]" %%x in ('find /n /v "" asuka.txt') do (
title woking on line nr %%x
for /f "tokens=1-6,*" %%a in ("@ %%y") do (
if "%%b"=="bbox" (
echo first.one %%c
echo second.two %%d
echo third.three %%e
echo fourth.four %%f
REM lines above: between 'echo' and text, there are a space and a TAB
REM lines above: and a TAB between text and '%%?'
) else echo/%%y
)
))>asuka.new
答案 1 :(得分:0)
我终于通过修改代码来破解它,感谢Stephan的所有帮助。我的项目有点大,然后这里的bbox就是完成的代码:
@echo off
setlocal enabledelayedexpansion
set tab=
(
for /f "tokens=* delims=[]" %%a in (input.txt) do (
for /f "tokens=1-15" %%b in ("%%a") do (
set attack=false
set atknum=0
if "%%b"=="attack" (
set attack=true
set atknum=1
) else if "%%b"=="attack2" (
set attack=true
set atknum=2
) else if "%%b"=="attack3" (
set attack=true
set atknum=3
) else if "%%b"=="attack4" (
set attack=true
set atknum=4
) else if "%%b"=="attack5" (
set attack=true
set atknum=5
) else if "%%b"=="attack6" (
set attack=true
set atknum=6
) else if "%%b"=="attack7" (
set attack=true
set atknum=7
) else if "%%b"=="attack8" (
set attack=true
set atknum=8
) else if "%%b"=="attack9" (
set attack=true
set atknum=9
)
if "%%b"=="bbox" (
echo %tab% bbox.position.x %%c
echo %tab% bbox.position.y %%d
echo %tab% bbox.size.x %%e
echo %tab% bbox.size.y %%f
) else if "!attack!"=="true" (
if "%%e"=="0" (
echo %tab% attack.damage.type !atknum!
echo %tab% attack.size.x 0
) else (
echo %tab% attack.damage.type !atknum!
echo %tab% attack.position.x %%c
echo %tab% attack.position.y %%d
echo %tab% attack.size.x %%e
echo %tab% attack.size.y %%f
echo %tab% attack.damage.force %%g
echo %tab% attack.reaction.fall.force %%h
echo %tab% attack.block.penetrate %%i
echo %tab% attack.effect.hit.flash.disable %%j
echo %tab% attack.reaction.pause.time %%k
echo %tab% attack.reaction.fall.velocity.y 2
echo %tab% attack.reaction.fall.velocity.x 2
)
) else if "%%b"=="hitflash" (
echo %tab% attack.effect.hit.flash.model %%c
) else if "%%b"=="hitfx" (
echo %tab% attack.effect.hit.flash.sound %%c
) else if "%%b"=="damageonlanding" (
echo %tab% attack.damage.land.force %%c
echo %tab% attack.damage.land.mode %%d
) else if "%%b"=="dropv" (
echo %tab% attack.reaction.fall.velocity.y %%c
echo %tab% attack.reaction.fall.velocity.x %%d
) else if "%%b"=="anim" (
echo.
echo %%a
) else echo %%a
))) >output.txt