长度为变量的 DOS 子字符串
我正在尝试在 DOS 批处理脚本中从变量中提取子字符串。据我了解,可以使用如下语句来执行此操作:
set substring=%original_string:~2,3%
其中 2 是从零开始的偏移量,3 是要提取的子字符串的长度。到目前为止,一切都很好,对吧?
但是,我需要我的长度是一个变量,而不是一个明确的数字。我几乎确信这是可以完成的,但是正确的语法让我困惑:-(
我尝试过的是...
set string=string
set length=3
set substring=%string:~0,%length%%
echo substring is: %substring%
我得到的是...
substring is: length%
我尝试删除一组百分号,但是...没有
人知道我是否可以做我想做的事???
谢谢!
I'm trying to extract a substring, from a variable, in a DOS batch script. As I understand it, one does this with a statement like the following:
set substring=%original_string:~2,3%
Where 2 would be a zero-based offset, and 3 would be the length of the substring to be extracted. So far, so good, right?
But, I need my length to be a variable, not a explicit number. I'm almost sure this can be done, but the proper syntax is eluding me :-(
What I have tried is...
set string=string
set length=3
set substring=%string:~0,%length%%
echo substring is: %substring%
What I get is...
substring is: length%
I've tried removing 1 set of percent signs, but... no good.
Does anyone know if and how I can do what I want???
thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改成这样:
Change it to this: