检查一个字符串中是否含有某个子字符串

      /**
* 检查一个字符串中是否含有某个子字符串
* 例如: "ABC_001"里面是否包含"ABC"字符串
* @author 
*/
public class Test {


public static void main(String[] args) {

String str="ABC_001";
 if(str.indexOf("ABC")==-1){      //str.indexOf("ABC")表示返回ABC在str中第一次出现的位置索引
  System.out.println("不包含");
 }else{
  System.out.println("包含");
 }
}
}
发布了31 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/SDBX_lyp/article/details/80834485
今日推荐