码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-05-17 10:08:14      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:san   ret   判断   color   hit   bottom   key   pos   字符   

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

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

标签:san   ret   判断   color   hit   bottom   key   pos   字符   

原文地址:http://www.cnblogs.com/huyanlon/p/6865712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!