String a = "HelloWorld";
String b = "oWor";
如何符合判断a中是否包含b?
String b = "oWor";
如何符合判断a中是否包含b?
解决方案 »
- 锁死问题
- 我该怎么办啊
- 要做关于javaee的课程设计,有几个技术要点不太明白,请指教
- 求助,关于ant和jdk1.5
- 怎么把它扒出来???
- 关于HttpURLConnection的问题,谢谢
- 谁有《Exploring Java, 2nd Edition》,100分求
- 为什么可以直接使用CharBuffer中的抽象方法get()和put()
- jdbc如果获取数据表字段的label(英文字段名的描述)
- 包含javaapplet的网页中.class文件一般保存在什么地方呢
- SQLServerDriver连接不上!!!!!!!!
- java当中有没有类似VB中的msgbox()和Inputbox()函数?
Returns the index within this string of the first occurrence of the specified substring.
a.indexOf(b)>=0a.indexOf(b)!=-1
}
public static void main (String[] args) {
String a = "HelloWorld";
String b = "oWor"; System.out.println(a.indexOf(b));
}
}输出 4 如果不包含输入为 -1public int indexOf(String str)
Returns the index within this string of the first occurrence of the specified substring. The integer returned is the smallest value k such that:
this.startsWith(str, k)
is true. Parameters:
str - any string.
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
public class RegexTest {
public static void main(String args[]) { Pattern pattern = Pattern.compile("oWor");
Matcher matcher = pattern.matcher("HelloWorld");
if(matcher.find()) {
System.out.println("Bingo!");
}else{
System.out.println("No substring here!");
} }
}