繁体   English   中英

字符串replaceAll()不起作用

[英]string replaceAll() is not working

我想从服务器的传入字符串中获取所需的内容。 我使用了下面的代码,但是它不起作用。

ServerResponse = response.toString();
ServerResponse = ServerResponse.replaceAll("[\\d]", "");
list =ServerResponse.split("\n");

但这不起作用,我得到的名单

[1234] apple
[1122] Linux
[3344] window 

我只想得到

apple
Linux
windows

尝试下一个regEx \\\\[\\\\d*\\\\] ,它对您有帮助。

尝试这个:

ServerResponse = ServerResponse.replaceAll("\\[\\d*\\]", "");
list =ServerResponse.split("\n");

它会工作。

试试这个:

String[] temp = serverResponse.split("[");
for(String str : temp){
    list.add(str.substring(4));
}

最后,您有了所需的列表。

尝试这个:

 ServerResponse = response.toString();
 ServerResponse = ServerResponse.replaceAll("[^a-zA-Z]", ""); 
 list =ServerResponse.split("\n");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM