Board logo

标题: [文本处理] 帮忙看看批处理错出在哪里吧 [打印本页]

作者: an410398183    时间: 2013-5-22 10:17     标题: 帮忙看看批处理错出在哪里吧

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "delims=" %%i in (test.txt) do (
  4. set testvalue=%%i
  5. set num=
  6. for /f "delims=. tokens=1" %%i in ("!testvalue!") do (set num=%%i)
  7. set replace=!num!.
  8. set testvalue=!testvalue:%replace%=!
  9. echo !testvalue!
  10. )
  11. pause
复制代码
期望输出结果如下:
test
value
hello world

实际输出结果如下:
testvalue:=
testvalue:=
testvalue:=
Press any key to continue . . .

test.txt  文件中的内容如下
1.test
2.value
3.hello world
作者: tmplinshi    时间: 2013-5-22 10:25

本帖最后由 tmplinshi 于 2013-5-22 10:28 编辑
  1. set testvalue=!testvalue:%replace%=!
复制代码
改成
  1. for %%a in ("!replace!") do set testvalue=!testvalue:%%~a=!
复制代码
————————————————————————————————————————————

如果只是获取第一个点后面的字符,可以这样:
  1. @echo off
  2. for /f "tokens=1,* delims=." %%a in (test.txt) do (
  3.     echo %%b
  4. )
  5. pause
复制代码

作者: an410398183    时间: 2013-5-22 10:33

回复 2# tmplinshi
先谢谢版主了!!
这样确实可以了。但这是为什么呀?
这是哪方面的知识点,指点下,我自己去查也可以
作者: Batcher    时间: 2013-5-22 10:34

回复 3# an410398183


变量延迟扩展、变量嵌套
http://www.bathome.net/thread-2899-1-1.html
作者: an410398183    时间: 2013-5-22 10:42

回复 4# Batcher
多谢指点




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2