Java: Remove brackets / leading slashes from String

My Android-app have always presented the DNS-Server(s) with brackets / leading slashes like:

How can we get rid of these unnecessary characters ?

String myIp2Dns1:

String myIp2Dns1 = String.valueOf (LinkProp.getDnsServers()) ;


Log.d("myDnsInfo - Domain - ", "Domain = " + LinkProp.getDomains());
D/myDnsInfo: dns = [/]

Manipulation of String myIp2Dns1:

myIp2Dns1 = myIp2Dns1.replaceAll("[\\[\\](){}\"^/+\"]","");

This command removes brackets / slashes / backslashes from the String.

The output looks much better now:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.