CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 20

Threaded View

  1. #20
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: determining if a string is an ip address or a hostname?

    If I was trying to solve this I would probably do it like this.

    Assuming you have a function like this...
    std::vector<std::string> Split(const std::string &text, char delimiter)

    Split the string at every ':'
    For an IP address you should have either one or two elements.

    Split the first element at every '.'
    For an IP address you should have four elements.

    Check that all elements in both vectors are integers between 0 and 255.
    EDIT: Except for the port number of course.
    Last edited by JohnW@Wessex; March 9th, 2009 at 04:28 AM.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured