批处理文件:是否有可能抽取子,其中指数是变量? [英] Batch File: Is it possible to extract a substring where the index is a variable?

查看:182
本文介绍了批处理文件:是否有可能抽取子,其中指数是变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两个变量,字符串首页,我想提取从索引开始的子串,我可以使用 SET 命令来做到这一点?例如:

  @ECHO关闭
SET字符串=您好
SET指数= 3
ECHO%字符串:〜%指数%%

这将返回 Helloindex%时,预期的结果是。正是我试图做可能吗?

问候,

安德鲁


解决方案

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET字符串=您好
SET指数= 3
!ECHO字符串:〜%索引%!
GOTO:EOF

当然可以。这里有一种方法,使用delayedexpansion。

哪种方法,你可以使用取决于什么挺你的意图和参数。你的问题实在是太一般了解决方案和特殊情况下的群众。

If I have two variables, string and index, and I want to extract a substring starting from the index, can I use the SET command to do this? For example:

@ECHO off
SET string=Hello
SET index=3
ECHO %string:~%index%%

This returns Helloindex% when expected result is lo. Is what I am trying to do possible?

Regards,

Andrew

解决方案

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET string=Hello
SET index=3
ECHO !string:~%index%!
GOTO :EOF

Certainly. Here's one way, using delayedexpansion.

Which method you might use depends on quite what your intentions and parameters are. Your question is really too general for the multitude of solutions and special cases.

这篇关于批处理文件:是否有可能抽取子,其中指数是变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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