/**
* 检查一个字符串中是否含有某个子字符串
* 例如: "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("包含");
}
}
}
* 检查一个字符串中是否含有某个子字符串
* 例如: "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("包含");
}
}
}
本文提供了一个简单的Java程序示例,展示了如何检查一个字符串是否包含另一个子字符串。使用了indexOf方法来实现这一功能,并通过一个具体的例子进行了说明。
3515

被折叠的 条评论
为什么被折叠?



