Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何更改在FOR/DO语句|批处理中查找的变量_Batch File - Fatal编程技术网

Batch file 如何更改在FOR/DO语句|批处理中查找的变量

Batch file 如何更改在FOR/DO语句|批处理中查找的变量,batch-file,Batch File,如何更改在for/Do语句中查找的变量 @ECHO off set Riddle=The Bird In The The Bush SET /a count=0 FOR (The) IN (%Riddle%) DO SET /a count=%count%+1 ECHO %count% 在这种情况下,是我想要寻找的变量, 但我认为这不是正确的格式 输出: 3 这是代码的功能版本 @ECHO off set Riddle=The Bird In The The Bush SET /a coun

如何更改在for/Do语句中查找的变量

@ECHO off
set Riddle=The Bird In The The Bush
SET /a count=0
FOR (The) IN (%Riddle%) DO SET /a count=%count%+1
ECHO %count%
在这种情况下,是我想要寻找的变量, 但我认为这不是正确的格式

输出:

3

这是代码的功能版本

@ECHO off
set Riddle=The Bird In The The Bush
SET /a count=0
FOR %%a IN (%Riddle%) DO if "%%~a"=="The" SET /a count+=1
ECHO %count%

注意这是区分大小写的。要使其不敏感,请将if%%~a替换为if/i%%~a。

似乎需要计算字符串中某个子字符串的出现次数。不幸的是,批处理不是这类任务最合适的脚本语言。您必须通过一个行拆分器将回音变量的输出管道化,然后再次通过管道将其输出管道化才能找到/C。祝您好运。那么您会推荐哪种语言呢?Python是一种不错的选择