确定字符串是否有子字符串(单词) [英] Determining whether a string has a substring (word)
本文介绍了确定字符串是否有子字符串(单词)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用条件来验证字符串是否包含某个单词,例如:
我想使用方法(正则表达式?)来查找字符串是否包含 & SWE> clickable
。
I try to use a conditional to verify if a string contain a certain word, for example:
I want to use a method (regex?) to find if a string has the text "&SWE>clickable"
.
var text1 = "layer_legs";
var text2 = "layer_head&SWE>clickable";
if (....)
document.write ("the layer is clickable")
else
document.write ("the layer is not clickable")
我该怎么做?
推荐答案
if (text2.indexOf("&SWE>clickable") > -1) {
....
这篇关于确定字符串是否有子字符串(单词)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文