[英]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.