我有一個程序可以使用Jsoup獲取特定團隊中的曲棍球運動員的統計數據並將其放入單個字符串中。我想分開陣容,這樣我就可以得到每個球員在他們自己的字符串中的統計數據。這是我的代碼,並解釋說:將一個字符串分成多行
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://espn.go.com/nhl/team/stats/_/name/phi/philadelphia-flyers").get();
for (Element table : doc.select("table.tablehead")) {
for (Element row : table.select("tr")) {
Elements tds = row.select("td");
if (tds.size() > 6) {
String a = tds.get(0).text() + ":" + tds.get(1).text() + " GOALS: " + tds.get(2).text() + " ASSISTS: " + tds.get(3).text() + " POINTS: " + tds.get(4).text() + " PLUS/MINUS: " + tds.get(5).text() + " PIM: " + tds.get(6).text();
System.out.println(a);
}
}
}
}
輸出給多行,給你一個想法,這是第一次三行它給:
PLAYER:GP GOALS: G ASSISTS: A POINTS: PTS PLUS/MINUS: +/- PIM: PIM
Matt Read, C:13 GOALS: 5 ASSISTS: 4 POINTS: 9 PLUS/MINUS: 2 PIM: 2
Brayden Schenn, C:12 GOALS: 2 ASSISTS: 6 POINTS: 8 PLUS/MINUS: 3 PIM: 5
如果行的開頭=馬特·裏德我想打一個包含字符串:
Matt Read, C:13 GOALS: 5 ASSISTS: 4 POINTS: 9 PLUS/MINUS: 2 PIM: 2
如果行=佈雷登·施恩的開始,我想打一個包含字符串:
Brayden Schenn, C:12 GOALS: 2 ASSISTS: 6 POINTS: 8 PLUS/MINUS: 3 PIM: 5
謝謝!我不知道爲什麼我不能想到這一點。 – MaxK 2013-02-12 22:46:32