我想从sever的传入字符串中获取所需的内容。我使用了下面的代码,但它不起作用。
ServerResponse = response.toString();
ServerResponse = ServerResponse.replaceAll("[\d]", "");
list =ServerResponse.split("n");
但这不起作用,我得到的列表为
[1234] apple
[1122] Linux
[3344] window
我只想得到
apple
Linux
windows
尝试下一个正则表达式\[\d*\]
,它可以帮助你。
试试这个:
String[] temp = serverResponse.split("[");
for(String str : temp){
list.add(str.substring(4));
}
最后,你有你想要的列表。
试试这个:
ServerResponse = ServerResponse.replaceAll("\[\d*\]", "");
list =ServerResponse.split("n");
它会起作用。
试试这个:
ServerResponse = response.toString();
ServerResponse = ServerResponse.replaceAll("[^a-zA-Z]", "");
list =ServerResponse.split("n");