开发者

DOS Substring where Length is a Variable

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!


Change it to this:

call set substring=%%string:~0,%length%%%
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜