判断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("不包含"); 
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM