想知道,从字符串中的标题拉取信息的最佳方法是什么。从字符串中拉取标题 - Java
我有一个类和getter方法的标题(摘要,标题1,标题2)。
例如,
如果非要等于字符串,
This: is the first line of a String: xx-string: This is a long String
Summary:
This is the summary of the String
Heading 1:
This is the first heading
Heading 2:
This is another heading
什么是设置字符串的值以期望的方式,
摘要,标题1,标题2
到
Summary = This is the summary of the String
Heading 1 = This is the first heading
Heading 2 = This is another heading
谢谢!
编辑
这里是我要去的,
public void setHeadings(Data fileData) {
String description = fileData.getDescription();
//String [] headings = description.split(":");
int indexOf;
indexOf = description.indexOf("Summary");
if(indexOf != -1)
{
String subString = description.substring(indexOf);
int indexOfNextHeading = subString.indexOf(":");
if(indexOfNextHeading != -1)
{
System.out.println(indexOf + ":" + indexOfNextHeading);
setSummary(description.substring(indexOf,indexOfNextHeading-1));
System.out.println(description.substring(indexOf,indexOfNextHeading));
}
}
}
也就是说然而,吐出来的数组越界异常。
摘要和标题是多行段落吗?第一行怎么样?我们是否完全放弃第一行? – rmarimon 2012-07-11 14:25:58
听起来像作业...? – carlspring 2012-07-11 14:32:14
不做作业,我是实习生。第一个包含文本的框是** 1 **字符串 – TomSelleck 2012-07-11 14:33:18