我如何得到一个字符的位置从批次字符串 [英] How I get the position of a character from a string in batch

查看:220
本文介绍了我如何得到一个字符的位置从批次字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保存在一个结果字符串变量 RES ,这样的结果是一样的东西 2.3 / 5.0 我会像 / ,并通过 ECHO发送到批量输出命令之前得到的部分。我一直在寻找我怎么可以这样使用批处理命令,但只获得使子到一个固定位置的结果,但我怎么能知道这个职位?
如果我想知道的位置也许我应该做的唯一的事情是:

I have a result string saved in a variable RES, this result is something like 2.3/5.0 I would like to get the part before the "/" and sending it to the batch output through an ECHO command. I have been searching how can I do this using batch commands, but only getting results of making substring to a fixed position, but how can I know this position? If i would knew the position the only thing I should probably do is:

ECHO %RES:~0,pos%

接下来的问题是:我如何才能从字符串这个位置?谢谢

Then the question is: how I get this position from the string? Thanks

推荐答案

如果你真的想要自己的位置,你可以申请从strlen函数<一个href=\"http://stackoverflow.com/questions/5837418/how-do-you-get-the-string-length-in-a-batch-file\">How你得到的字符串长度在批处理文件下面的结果,但如果你只是想那个preFIX,你可以简单地做:

If you really want the position itself, you can apply the strlen function from How do you get the string length in a batch file? to the result below, but if you just want that prefix, you can simply do:

set "res=2.3/5.0"
for /f "tokens=1 delims=/" %%i in ("%res%") do (set prefix=%%i)

这篇关于我如何得到一个字符的位置从批次字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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