首页 > 解决方案 > 如何在命令提示符下修剪字符串?

问题描述

我在一个目录中有很多快捷方式 url。

C:\Users\Owner\Desktop\ReadItLaters>dir *.url /b
aaa.url
bbb.url
ccc.url

...

zzz.url

我想拿起那些网址。所以我写了这样的命令。

for %i in (*.url) do @type "%i" | find "URL=" 

像这样输出。

URL=https://www.example.com/aaa.html
URL=https://www.example.com/bbb.html
URL=https://www.example.com/ccc.html

...

URL=https://www.example.com/zzz.html

味道不错。但我想获取没有“URL =”的 url 字符串。

我希望这样输出。

https://www.example.com/aaa.html
https://www.example.com/bbb.html
https://www.example.com/ccc.html

...

https://www.example.com/zzz.html

如何将“URL =”替换为空?

标签: batch-filecmd

解决方案


您可以使用子字符串,跳过字符串中的前 4 个字符:%_url:~4%

/

for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:~4%

for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:~4%


推荐阅读