想知道,從字符串中的標題拉取信息的最佳方法是什麼。從字符串中拉取標題 - 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