gpt4 book ai didi

string - 批量匹配一个变量到另一个变量的一部分

转载 作者:行者123 更新时间:2023-12-01 15:30:18 25 4
gpt4 key购买 nike

我想批量匹配一个变量到另一个变量的部分内容。这是我想做的一些伪代码。

set h= Hello-World
set f= This is a Hello-World test

if %h% matches any string of text in %f% goto done
:done
echo it matched

有谁知道我怎样才能做到这一点?

最佳答案

基于 this answer here , 您可以使用 FINDSTR使用 /C 开关比较字符串的命令(从链接的答案修改,因此您不必有单独的批处理文件来比较字符串):

@ECHO OFF

set h=Hello-World
set f=This is a Hello-World test

ECHO Looking for %h% ...
ECHO ... in %f%
ECHO.

echo.%f% | findstr /C:"%h%" 1>nul

if errorlevel 1 (
ECHO String "%h%" NOT found in string "%f%"!
) ELSE (
ECHO String "%h%" found in string "%f%"!
)

ECHO.

PAUSE

关于string - 批量匹配一个变量到另一个变量的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19056911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com