如何在bat文件中执行字符串操作 [英] How to perform string operation in bat file
本文介绍了如何在bat文件中执行字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的字符串
设置s ="c:\ test \ test1 \ test.exe"
我只需要回显"c:\\ test \ test \ test"的值
如何在批处理文件中做到这一点
i am having the string like that
set s="c:\test\test1\test.exe"
i need echo the value of "c:\\test\test\test" only
how to do that in batch file
推荐答案
^ ]
解决办法给定了,这是一个直接的代码解决方案,但变量不带引号...
The solution barneyman gave is spot on, here is a direct code solution but with the variable without the quotations...
@echo off
SET var=c:\test\test1\test.exe
@echo %var:~0,-4%
pause
基本上是什么
1)回声切换
2)创建变量字符串
3)将变量字符串从位置0回显到后面的字符-4处...因此它删除了.exe扩展名
4)暂停以查看结果
Basically what it does is
1) Switch of the echo
2) Creates the variable string
3) echo the variable string from position 0 to the back character -4 places...so it removes the .exe extension
4) pause to witness the result
使用〜p仅扩展到路径:
Use ~p to expand to path only:
echo %~ps
这篇关于如何在bat文件中执行字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文