Results 1 to 5 of 5
  1. #1
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default convert InetAddress to a string

    how do you convert an InetAddress to a string?

    InetAddres.toStrin() doesn't work

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,558
    Rep Power
    23

    Default

    Have you tried the toString() method? Notice the g.
    doesn't work
    What does that mean? Can you show the error message or whatever doesn't work?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    toString() is working perfectly for that, but not as you expecting. I hope that's why you are mess on it.

    How did you fine the InteAddress? getByName()? So in that case you get as a host, I mean as hostname literal with / sign. So you have do some manipulation to remove it.

    Java Code:
            InetAddress inet = InetAddress.getByName("193.125.22.1");
            System.out.println(inet.toString());

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    6

    Default

    Quote Originally Posted by Eranga View Post
    toString() is working perfectly for that, but not as you expecting. I hope that's why you are mess on it.

    How did you fine the InteAddress? getByName()? So in that case you get as a host, I mean as hostname literal with / sign. So you have do some manipulation to remove it.

    Java Code:
            InetAddress inet = InetAddress.getByName("193.125.22.1");
            System.out.println(inet.toString());
    Wow, Eranga,i see you have already read the book of Elliot about Java Networkingp

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by serjant View Post
    Wow, Eranga,i see you have already read the book of Elliot about Java Networkingp
    Yep, you know how I put attempt to find the book. Now I'm working on it lol. It's cool ha. Thanks pal, thanks a lot.

Similar Threads

  1. How to convert a string into a BigInteger
    By valery in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 01:32 PM
  2. how to convert String number to int
    By gabriel in forum New To Java
    Replies: 5
    Last Post: 08-02-2009, 03:46 PM
  3. convert a really big string (len 39) to bigdecimal
    By coolsig in forum Advanced Java
    Replies: 6
    Last Post: 06-14-2008, 02:48 AM
  4. convert string to a double?
    By javaMike in forum Advanced Java
    Replies: 2
    Last Post: 11-27-2007, 03:10 AM
  5. convert string to float
    By miss_dot in forum NetBeans
    Replies: 1
    Last Post: 11-14-2007, 11:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •