判断java或js中的某个字符串中是否包含有某个字符或是字符串

js中:

varCts ="aaddssyes";

if(Cts.indexOf("yes") > 0 ){

alert('Cts中包含Text字符串');

}

找的是最开始的位置,如果没找到,则返回的是-1.

functionIndexDemo(str){

varstr1 ="BABEBIBOBUBABEBIBOBU"

vars = str1.indexOf(str);

return(s);

}

str是外边传来的一个字符串

java中:

public static void main(String[] args) {

String str="ABC_001";

if(str.indexOf("ABC")!=-1){

System.out.println("包含");

}else{ System.out.println("不包含");

}

}