2

When i convert string ("192.168.0.105") to InetAddress in java (android). I am getting "/192.168.0.105". An extra "/" is coming in InetAddress, which causes the socket not to be created.

How do i get rid of "/".

Regards,

Syed Mustehsan Ikram

jmj
  • 237,923
  • 42
  • 401
  • 438
Mustehsan Ikram
  • 218
  • 2
  • 4
  • 15

2 Answers2

7

You can use getHostAddress() method of InetAddress to get host address without /.

And if you are using InetSocketAddress then use getAddress().getHostAddress() to get host ip without /.

InetAddress inetAddress = InetAddress.getByName("192.168.0.105");
System.out.println(inetAddress.getHostAddress());

InetSocketAddress address = new InetSocketAddress("192.168.0.105", 5555);
System.out.println(address.getAddress().getHostAddress());
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
2
myString = myString.replace("/", "");
aroth
  • 54,026
  • 20
  • 135
  • 176