3

clientpsseabq" " 文字列が variableVar_wordsに含まれている場合は equal true、そうでない場合はそれを達成したいと思いますfalse。どのメソッドまたは関数を使用する必要があるのか​​ わかりませんか?

var Var_words = "https://www.go.me/outputsearchs/clientpsseabq"

if ( Var_words contains string "`clientpsseabq`"){
   return true;
}else{
   return false;
}

誰かが私を助けることができる場合、どうすればこのタスクを完了することができますか?

4

4 に答える 4

3

これを試すことができます

if (Var_words.indexOf("clientpsseabq") >= 0)

または大文字と小文字の区別に注意してください

if (Var_words.toLowerCase().indexOf("clientpsseabq") >= 0)
{
   // your code
}
于 2013-04-22T09:04:29.527 に答える
3

(ネイティブ JavaScript) 関数を使用しますString.indexOf()

if(Var_words.indexOf('clientpsseabq') !== -1) {
    return true;
} else {
    return false;
}

.indexOf()文字列のインデックスを返します。文字列が見つからない場合は、 を返します-1

より小さく、よりクリーンなソリューションは、条件の値を直接返すことです。

return (Var_words.indexOf('clientpsseabq') !== -1);
于 2013-04-22T09:05:04.583 に答える
1
 if(Var_words.indexOf("clientpsseabq") >= 0))
 {

 }
于 2013-04-22T09:06:28.097 に答える
1

正規表現を使用してケースをテストします

if(/clientpsseabq/.test(Var_words)){
    //given string exists
} else {
    //given string does not exists
}
于 2013-04-22T09:06:35.950 に答える