如何替换 !line! 中的 %pdf%批量
我有一个脚本,我需要在其中使用类似于 this 的测试(布尔测试“确实字符串存在吗?”)。在手册的示例中,使用了正常的%variable%,但我启用了延迟扩展。在我的代码中,我需要从 !line! 中删除 %pdf% 。 我的意图是像 链接 中那样执行类似操作(示例,SET _endbit,其中 %使用了variable%)
这是我的代码:
@echo off
setlocal EnableDelayedExpansion
set "source=GEN 0 GENERAL.html"
set "pdf=0_1_en.pdf"
echo In file:%source%
echo Look for anchor:%pdf%
rem Process each line in %source% file:
for /F "usebackq delims=" %%c in ("%source%") do (
set "line=%%c"
rem Test if the line contain a pdf file I look for
echo on
cls
echo Line: !line!
REM PROBLEM HERE WITH VARIABLE !line! ? Need to replace %pdf% in !line!
CALL SET "pdfline=%%line:%pdf%=%%"
if not "!pdfline!" == "!line!" (
echo Line: !line!
CALL SET tagline=%%tagline:%pdf%=%%
echo ACTUAL LINE: %tagline%
pause
)
)
pause
关键在第17行,我想从变量中删除pdf文件。你能帮忙吗?
该脚本搜索 html 文件中的某些文本。文本设置为 pdf 文件名。如果需要,您可以在任何 html 文件上测试它。
I have a script in which I need to use test similar to this (Boolean Test "does string exist ?"). In the example in manual, there is used normal %variable%, but I have Enabled Delayed Expansion. In my code I need to remove %pdf% from !line! .
My intention was to do it similar like in the link (Examples, SET _endbit, where %variable% is used)
Here is my code:
@echo off
setlocal EnableDelayedExpansion
set "source=GEN 0 GENERAL.html"
set "pdf=0_1_en.pdf"
echo In file:%source%
echo Look for anchor:%pdf%
rem Process each line in %source% file:
for /F "usebackq delims=" %%c in ("%source%") do (
set "line=%%c"
rem Test if the line contain a pdf file I look for
echo on
cls
echo Line: !line!
REM PROBLEM HERE WITH VARIABLE !line! ? Need to replace %pdf% in !line!
CALL SET "pdfline=%%line:%pdf%=%%"
if not "!pdfline!" == "!line!" (
echo Line: !line!
CALL SET tagline=%%tagline:%pdf%=%%
echo ACTUAL LINE: %tagline%
pause
)
)
pause
The key is on line 17, where I want to remove the pdf file from the variable. Can you help?
The script searches certain text in html file. The text is set to pdf filename. You can test it on any html file if you want to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要从行中删除 %pdf% 的值,则使用此
如果您想从行中删除文字字符串“%pdf%”,则使用此
If you want to remove the value of %pdf% from the line, then use this
If you want to remove the literal string "%pdf%" from the line, then use this