标题: [文本处理] [已解决]求助批处理if语句内拼接字符串为什么不行? [打印本页]
作者: hardstone 时间: 2024-5-22 18:59 标题: [已解决]求助批处理if语句内拼接字符串为什么不行?
本帖最后由 hardstone 于 2024-5-23 09:19 编辑
- set M=@
- if "1" == "1" (
- echo !!!!!!!!!!
- echo 0%M%
- set "x=0%M%"
-
- echo %x%?
- :: why it echo just one
- echo !!!!!!!!!!
- )
复制代码
echo出的结果是?而不是0@?
作者: 77七 时间: 2024-5-22 20:59
- @echo off
- set M=@
- if "1" == "1" (
- echo !!!!!!!!!!
- setlocal enabledelayedexpansion
- echo 0!M!
- set "x=0!M!"
-
- echo !x!?
- endlocal
- rem why it echo just one
- echo !!!!!!!!!!
- )
- pause
复制代码
参考: [教程汇总]批处理中的变量延迟扩展、变量嵌套
作者: ShowCode 时间: 2024-5-22 21:36
回复 1# hardstone - @echo off
- setlocal enabledelayedexpansion
- set "M=@"
- if "1" == "1" (
- echo ----------
- echo 0%M%
- set "x=0%M%"
- echo !x!
- echo ----------
- )
- pause
复制代码
作者: aloha20200628 时间: 2024-5-22 22:17
本帖最后由 aloha20200628 于 2024-5-22 22:25 编辑
回复 1# hardstone
除了采用变量延迟应对 ‘预处理’,还可采用call+%%v%%方法应对 ‘预处理’ ...
- @echo off
- set M=@
- if "1" == "1" (
- echo !!!!!!!!!!
- echo 0%M%
- call set "x=0%%M%%"
- call echo %%x%%?
- echo !!!!!!!!!!
- )
复制代码
作者: hardstone 时间: 2024-5-23 09:17
谢谢大佬们解答!
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |