本文介绍了批处理文件,如果字符串以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道一个字符串是否以某个东西开头,产生了这个小例子来解释(我使用批处理编译器/预处理器或带有高级命令的任何东西):

I need to know if a string starts by something, produced this little example to explain (I'm using a Batch compiler/Pre-processor or whatever with advanced commands) :

rem GetInput
if "%result%"=="cd *" goto Cd
:Cd
if "%result%"=="cd meow" Echo Going to directory 'meow'...

但是此代码不起作用,如果字符串%result%以字母cd开头,则脚本不要转到:Cd处.

But this code doesn't work, at the line with a "cd *" the script dont go to :Cd if the string %result% starts with the letters cd.

谢谢

推荐答案

如果我正确理解这一点,则您正在尝试确定%result%的值是否以"cd"开头,并且您无法成功使用 * 作为通配符来确定它.

If I understand this correctly, you're trying to determine whether that value for %result% begins with 'cd', and you're unsuccessfully using a * as a wildcard to determine this.

有几种不同的处理方法.这是一种方法:您可以检查前两个字符是否等于'cd':

There are a few different ways to handle this. Here's one way: You can check to see if the first two characters are equal to 'cd':

if /i "%result:~0,2%"=="cd" goto Cd

set/?对此有更多说明.

这篇关于批处理文件,如果字符串以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 07:38