我想知道如何将长字符串的一部分带到字符串数组中。
例如turing:
String str = "hi im john and my email is <john@hotmail.com> and my number is <0123456789>"
至String[] strarray = {"john@hotmail.com", "0123456789"}
答案 0 :(得分:3)
这样的事情会起作用:
public static void main(String... args) throws Exception {
String str = "hi im john and my email is <john@hotmail.com> and my number is <0123456789>";
Pattern p = Pattern.compile("<(.*?)>");
Matcher m = p.matcher(str);
while(m.find()) {
System.out.println(m.group(1));
}
}
O / P:
john@hotmail.com
0123456789