只是想知道,从字符串中的标题中提取信息的最佳方法是什么。
我有一个用于标题的类和 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));
}
}
}
然而,这会吐出一个 Array Out of bounds 异常。