简体   繁体   中英

string replaceAll() is not working

I want to get the desired content from an incoming string from sever. I have used below code but it is not working.

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

but this is not working and I am getting the list as

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

I want to get only

apple
Linux
windows

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

try this:

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

it will works.

Try this one :

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

And finally, you have the list you want.

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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