String str="交足應向接收該信件<Page>1</Page>者計其少交<B>之數</B>照收加<Nation>66</Nation>倍 其各項不能代寄之<I>物特爲詳列</I>於後 一除信函以外其各<Page>1</Page>項物件若未經交足<Nation>67</Nation>寄資或先付若干及其物件有未遵前章辦理而欲照章受其<B>減少寄資</B>";
//<text>交足應向接收該信件</text><Page>1</Page><text>者計其少交</text><B>之數</B><text>照收加</text><Nation>66</Nation>
/**说明:把标签保留下来,和标签内容保留下来,放到List集合中
* text 交足應向接收該信件
* Page 1
* text 者計其少交
* B 之數
* text 照收加
* Nation 66
*/
解决方案 »
- struts2 写的一个HelloWorld出问题,求指导
- 谁有多余的QQ号 批量给我点~!!!
- 在IntelliJ IDEA 中部署应用程序到JBoss服务器上出现的问题
- iframe中JSP页面跳转的问题------急急急!!在线等
- JAVA解析文本本件并保存入库
- weblogic中配置正确,但在jbuilder中运行时说找不到jndi,为何?(急,多谢!)
- 超级怪事:一个在JBuilder9中加在jdbc驱动的问题
- 请问如何配置weblogic的cluster
- 下列代码显示错误
- 求救:怎么样同过java编程把internet上的图片下载到本地??给点思路有分!!!
- 请问MyEclipse怎么把右键工程-->new-->页面快捷创建按钮显示出来呢?
- 哪些人用tomcat
是做成这样:
<text>交足應向接收該信件</text><Page>1</Page><text>者計其少交</text><B>之數</B><text>照收加</text><Nation>66</Nation>
?
* text 交足應向接收該信件
* Page 1
* text 者計其少交
* B 之數
* text 照收加
* Nation 66
*/
public static List<String> getInfo(String str){
List<String> result = new ArrayList<String>();
int firstIndex = str.indexOf("<");
int secondIndex = str.indexOf(">", firstIndex);
if(firstIndex < 0){
if(str.length() > 0){
result.add("text=" + str);
}
return result;
}
String key1 = str.substring(firstIndex + 1, secondIndex);
int endIndex = str.indexOf("</" + key1 + ">", secondIndex);
if(endIndex > 0){
if(firstIndex > 0){
result.add("text=" + str.substring(0, firstIndex));
}
result.add(key1 + "=" + str.substring(secondIndex + 1, endIndex));
str = str.substring(endIndex + key1.length() + 3);
}else{
result.add("text=" + str.substring(0, firstIndex) + 1);
}
result.addAll(getInfo(str));
return result;
}这样就能生成List集合了,不过方法比较粗略,str混乱的话会有意外