|
|
本帖最后由 pcl_test 于 2016-9-13 20:44 编辑
小女在写替换脚本程序时遇到如下问题,哪位前辈知道一下:
原字符串:sd"hello"vc
替换后的字符串:sd"world"vc
功能:检测出原字符串中双引号中的hello,再用world将其替换,最后的输出为sd"world"vc
自己写的脚本如下- @echo off
- setlocal enabledelayedexpansion
- for /f tokens^=1-2*delims^=^" %%i in ("sd"hello"vc") do echo %%j
- set str=sd"hello"vc
- set substr=%%j
- set replace=world
- echo %substr%
- set "str=!str:%substr%=%replace%!"
- echo %str%
- pause
复制代码 遇到问题是在脚本第三行最后的%%j带出了hello,完了赋给substr,但是输出echo %substr%是却不是
hello而是%j,因此在替换这行:set "str=!str:%substr%=%replace%!",substr无效,请教一下怎么解
决啊 |
|