gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
在JS中,如何判断一个字符串中是否包含某个子串
- User
在JS中,如何判断一个字符串中是否包含某个子串
- Assistant
可以使用字符串的
includes方法来判断一个字符串中是否包含某个子串。例如:
let str = 'Hello World'; console.log(str.includes('Hello')); // true console.log(str.includes('world')); // false除此之外,也可以使用正则表达式来进行匹配。
例如:
let str = 'Hello World'; console.log(/Hello/.test(str)); // true console.log(/world/.test(str)); // false