gpt4 book ai didi

windows - 批量扫描子字符串

转载 作者:可可西里 更新时间:2023-11-01 11:07:24 24 4
gpt4 key购买 nike

我是批处理的新手,我正在尝试为一个项目制作一个“类脑”程序,它应该能够完成简单的简短对话。我正在使用 set/p 来询问用户问题,如下所示:

set /p a= Hello: 

我希望能够查看用户是否在他们的回答中说了一个特定的词,以帮助确定计算机将回复什么。

谢谢。

最佳答案

@echo off
set "specific_word=something"

set /p a= Hello:


setlocal EnableDelayedExpansion
if /I not "!a:%specific_word%=!" EQU "!a!" (
echo it contains the word
) else (
echo it does not contain the word
)


echo %a%|find /i "%specific_word%" >nul 2>&1

echo --OR--

if errorlevel 1 (
echo it does not contain the word

) else (
echo it contains the word
)

IF 方法更快。

关于windows - 批量扫描子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24883787/

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