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