日期:2014-05-20  浏览次数:20625 次

java截取字符串
字符串s= "fabwoeiwoiedabeddd "怎么截取两个 "ab "之间的那部分 "woeiwoied ".

------解决方案--------------------
"fabwoeiwoiedabeddd ".split( "ab ")然后去掉一头一尾
------解决方案--------------------
s.substring(s.indexOf( "ab "),s.lastIndexOf( "ab "));
------解决方案--------------------
String str = "fabwoeiwoiedabeddd ";
String temStr = str.substring(str.indexOf( "ab ")+2);
String endStr = temStr.substring(0,temStr.indexOf( "ab "));
System.out.println(endStr);
------解决方案--------------------
public String substring(int beginIndex,
int endIndex)
参数:
beginIndex - 开始处的索引(包括)。
endIndex - 结束处的索引(不包括)。
******************************************
String s= "fabwoeiwoiedabeddd ";
s.substring(3, 12);
------解决方案--------------------
s= "fabwoeiwoiedabeddd "
int i = s.indexof( "ab ");
int j = s.indexof( "ab ",i);
s1 = s.substring(i,j);
------解决方案--------------------
"(ab)(.*)(ab) "
------解决方案--------------------
也可以用正则来实现.
------解决方案--------------------
用正则表达式会好点。
------解决方案--------------------
高手真不少
------解决方案--------------------
String s= "fabwoeiwoiedabeddd ";
String getStr ;
Pattern p2 = Pattern.compile( "(ab)(.*)(ab) ");
Matcher m2 = p2.matcher(s);
while(m2.find()){
System.out.println( "**************** ");
getStr = m2.group(2);
System.out.println(getStr);
}

不知道是不是你想要的,用正则表达式写的