子串选择中的嵌套变量 [英] Nested Variables in Substring selection

查看:77
本文介绍了子串选择中的嵌套变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使此子字符串"-选择动态完成:

I'm struggling to get this "Substring"-Selection done dynamically:

set input=%input:~4%

我想要类似

set input=%%input:~%length% %%

但是我所有的尝试都使用了%%和的两倍!还有更多失败了.希望您能告诉我,这样的嵌套变量在Windows批处理文件中如何工作.

But all my attempts with double %% and ! and many more have failed. Hope you can tell me, how nested variables like this work in windows batch files.

在此先感谢

最诚挚的问候,

马库斯

推荐答案

许多可能的方式

这使用了CALL第二次启动批处理解析器的事实

This uses the fact that CALL starts the batch parser a second time

set length=4
call set input=%%input:~%length%%%

延迟扩展是最稳定,最安全的解决方案

With delayed expansion it's the most stable and secure solution

setlocal EnableDelayedExpansion
set length=4
set input=!input:~%length%!

有时候使用FOR参数甚至更有用

Sometimes it's even useful to use a FOR parameter

setlocal EnableDelayedExpansion
set length=4
for /F %%n in ("!length!") do (        
    set input=!input:~%%~n!
)

这篇关于子串选择中的嵌套变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆