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)
哦,你可以給我按摩?我的背痛。 ':P'(消息的固定拼寫) – Doorknob 2013-03-18 13:08:58
您的模式已修復? – 2013-03-18 13:12:46
是的..它更像是一個堅實的形式 – AACaN 2013-03-18 13:15:10