const str = "はじめまして!codingEverybodyです。";

console.log(str.includes("codingEverybody")); // 出力: true
console.log(str.includes("CODINGEVERYBODY")); // 出力: false(大文字と小文字を区別)
str.includes(searchString)
str.includes(searchString, position)
const haystack = "Hello, World!";
const needle = "world";

const isNeedle = haystack.includes(needle); // false(大文字と小文字を区別)

if (isNeedle) {
    console.log(`文字列に'${needle}'が含まれています。`);
} else {
    console.log(`文字列に'${needle}'が含まれていません。`);
}

// 出力: "文字列に'world'が含まれていません。"
const haystack = "Hello, World!";
const needle = /Hello/; // 正規表現は使用できません。TypeErrorが発生します。

const isNeedle = haystack.includes(needle);

if (isNeedle) {
    console.log(`文字列に'${needle}'が含まれています。`);
} else {
    console.log(`文字列に'${needle}'が含まれていません。`);
}
const haystack = "ようこそ。";
const needle = "";

const isNeedle = haystack.includes(needle);

console.log(isNeedle); // 空文字列は常にtrueを返します。
const txt = "私はリンゴとバナナが好きです。";
const searchTerm = "リンゴ";

if (txt.includes(searchTerm)) {
    console.log(`テキストに'${searchTerm}'という単語が含まれています。`);
} else {
    console.log(`テキストに'${searchTerm}'という単語が含まれていません。`);
}

// 出力: "テキストに'リンゴ'という単語が含まれています。"
const content = 'この文章には望ましくない単語が含まれています。';
const unwantedWords = ['望ましくない', '悪い', '不適切な'];

unwantedWords.forEach(unwantedWord => {
    if (content.includes(unwantedWord)) {
        let filteredContent = content.replace(unwantedWord, "***");
        console.log(filteredContent);
    }
});

// 出力: "この文章には***単語が含まれています。"
// 大文字と小文字を区別せずに 'hello' 文字列を検索
const searchStr = "hello";
const str = "Hello, world! hello, universe!".toLowerCase();

let count = 0;
let startIndex = 0;

while (str.includes(searchStr, startIndex)) {
    count++;
    startIndex = str.indexOf(searchStr, startIndex) + 1;
}

console.log("検索する文字列の出現回数:", count);
// 出力: 検索する文字列の出現回数: 2