2016-03-18 18 views
1

入力文字列を別の文字列と比較したいのですが、一致しない場合は文書に書きたいと思います。私はこれを思いついた:バッチを比較する文字列を比較する

echo Correct this sentence: 
echo ---------------------- 
echo. 
echo 'me has been shoppping with my freinds' 

set sentence1= 
set /p sentence1=Answer: 
echo Your answer was: "%sentence1%" 
pause 

誰かがヒントを持っていますか?

+1

「IF」%string1%」equ「%string2%」エコー文字列が等価である – npocmaka

+0

非equのようなものがありますか? –

+0

Yep - 'IF NOT"%string1% "equ"%string2% "エコー文字列が等しくないか' IF "%string1%" neq "%string2%"エコー文字列が等しい " – npocmaka

答えて

0

文章をファイルに保存する場合は、%sentence1%==%sentence2%という単純なものを使用するか、findを使用します。

if not %sentence1%==%sentence2% (
    echo %sentence1% > file.txt 
    ::to append use ">>" 
) 

または

echo 'me has been shoppping with my freinds' > file.txt 
find "%sentence1%" in "file.txt" 
if %errorlevel%==1 (
    echo Sentence is not the same 
) 

そして findはまた、唯一の単語が十分であるように動作し、単語がファイル内に存在する場合、それが文を見つけたように、それは動作しますよ。たとえば、 "me"は文章を同じとマークしますが、 "me with"はそうではありません。 secndオプションは、特定の単語/単語の組み合わせを間違いの対象にする場合などに便利です。 "me has"