trim()是去掉首尾空格,不能去中间空格的
StringBuffer strBuf = new StringBuf();
int startIndex = 0;
int endIndex = str.indexOf('b');
while(startIndex <= str.length()){
  if(0 > endIndex)endIndex = str.length();
  strBuf.append(str.subString(startIndex,endIndex);
  startIndex = endIndex + 1;
  endIndex = str.indexOf('b',startIndex);
}//没运行过,试试吧,给个思路而已:)