My String就像
String body = "GH 1234 RING 5";
我想将数字1234,RING和最后5个提取到单独的变量中,并希望比较每个值。它会像.. pass = 1234,cmnd = RING和duration = 5就像这样.. 请帮我弄清楚如何实现这一目标。 我喜欢
String body="GH 1234 RING";
String pass=bodypass = body.replaceAll("[^0-9]", "");
获取1234.但我找不到如何检索RING和5.
答案 0 :(得分:1)
这样做
String body = "GH 1234 RING 5";
String[] splited = body.split("\\s+");
现在这将是结果
splited[0] = GH
splited[1] = 1234
splited[2] = RING
splited[3] = 5