Originally posted by Nee Kat:
I am getting an IPaddress in this form:
String ip_address = "172.17.91";
I want to remove the "." and convert this to an integer e.g. (Convert "172.17.91" to 1721791)
But replaceAll() is not working and if I use replace() then I am unable to substitute "." with blank spaces. And if I substitute with a blank space then parseInt() doesn't works.
Thanks,
Nee
I very much suspect you don't actually want to do this. Doing this makes the number ambiguous - not a good characteristic for an address!
E.g. 17217911 could be any of the following: 17.217.9.11, 172.179.1.1, 17.2.179.11 etc.
As M Beck points out, what you probably want to do is convert it from dotted decimal form, and pack the bytes into another type.
To achieve this, you might want to look at the
InetAddress class, and in particular the getAddress() method.
This return a byte array which you can then pack into an appropriate primitive type. I'll leave this bit up to you
Finally be aware that there are 32-bit IPv4 addresses which are 32-bits and IPv6 addresses which are 128-bit.