这些天我正试图为我学校的板球比赛制作一个记分牌小部件。而且我已经创建了一个小部件,可以从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)
答案 0 :(得分:1)
使用Java?看看
String.split()
如果你的图案是固定的,你应该能够按位置拆分和访问这些图块。 如果模式更具动态性,则必须使用
的组合String.subString() / String.indexOf()
答案 1 :(得分: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)