-3

这些天来,我正在尝试为学校的板球比赛制作记分牌小部件。我已经创建了一个从 twitter 获取消息的小部件。现在我需要将消息分成几部分并显示在小部件中。

例如-> 当小部件接收到的推文为

          Home scored 50 for 8 wickets and guest scored 60 for 5 wickets and batting.

我希望我的小部件显示

          Home = 60 wickets= 8
          Guest = 50 wickets=5 (Batting)
4

2 回答 2

1

使用Java?看一眼

String.split()

如果您的模式是固定的,您应该能够按位置拆分和访问碎片。如果模式更具动态性,则必须使用以下组合

String.subString() / String.indexOf() 
于 2013-03-18T13:19:35.663 回答
0
public static void main(String[] args) {
    String s = "Home scored 50 for 8 wickets and guest scored 60 for 5 wickets and batting.";
    String result = "";
    int homeScored = s.indexOf("scored");
    int guestScored = s.lastIndexOf("scored");
    int homeWicket = s.indexOf("for");
    int guestWicket = s.lastIndexOf("for");

    result = "home =" + s.substring(homeScored + 6, homeWicket)
            + "wicket ="
            + s.substring(homeWicket + 3, s.indexOf("wickets")) + "\n"
            + "guest = " + s.substring(guestScored + 6, guestWicket)
            + "wicket ="
            + s.substring(guestWicket + 3, s.lastIndexOf("wickets"))
            + "(batting)";
    System.out.println(result);
}

输出:

home = 50 wicket = 8 
guest =  60 wicket = 5 (batting)
于 2013-03-18T13:39:57.583 回答