从一段微博中提取除微博用户名子之外的内容算法:字符串截取算法
/** * 从一段微博中提取除微博用户名子之外的内容算法:字符串截取算法 * 例如:@zhang dsfsdfsd @uuu @000 fdsfdss " * * 输出: dsfsdfsd fdsfdss * * 输出结果要求:每一个小段的正文内容前后有一个 空格。 * @return * @author zxy */ public static String filterWeiboContent(String temp){ char chs[]= temp.toCharArray(); int i=0; boolean end = false; StringBuffer buf = new StringBuffer(); while(i<=chs.length-1){ if(end){ break; } char ch = chs[i]; if(ch == '@'){ buf.append(' ');//后面加空格 while(true){ int later = i+1; if(later==temp.length()){ buf.append(' '); end = true; break; } ch = chs[i++]; if(ch == ' '){ break; } } }else{ i++; //前面有一个空格了 if(ch!=' '){ buf.append(ch); } } } return buf.toString(); }