Java – Android replaces multiple characters from a string
•
Java
I know it may be an amateur problem, but for some reason, I don't remember how to do it
String s ="["; String q ="]";
If my text contains any of these, I want to replace it with W:
String w = "";
I have tried the following methods:
output=String.valueOf(profile.get("text")).replace(s&&q,w);
According to my understanding, if s ([) and any Q (]) are in the text, they will be replaced by W. my problem is to get 2 If I only try to replace one, then it will work Otherwise it won't
Any help will be greatly appreciated
Solution
You can also nest them:
output=String.valueOf(profile.get("text")).replace(s,w).replace(q,w);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码