String a = "HelloWorld";
String b = "oWor";
如何符合判断a中是否包含b?
String b = "oWor";
如何符合判断a中是否包含b?
解决方案 »
- 需要7m,11m,17m的管子各10根,至少需要多少根100m的管子,并求出每根管子的利用率
- 关于中英文解析问题的解决办法
- 问一个算法的问题?????
- String
- JSP制作的简单网页求助
- 匹配这个字符串的正则表达式怎么写?"用户1-ww-1-8#用户2-eeeee-1-9#……"其中……代表可能有一个或者多个!谢谢!
- 关于内存的搭配问题:)
- 初学者学JAVA用什么书好呢?
- Timer.schedule delay很小有可能不执行么?
- 清除ComBox中所有项的方法是CleanItem还是别的什么?
- 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!");
} }
}