Port in IPAddress

I get a string ,representing ip address .It has format ip:port I need to generate IPAddress .Will use for that :

public static IPAddress Parse(
    string ipString
)

The IPAddress which I need to get should not contain the data regarding a port. Does parse support that? If not how is it possible to done?

Jon Skeet
people
quotationmark

Assuming there's there's always a port and it's always represented by :<port number>, you can just unconditionally remove the part after the last colon:

int portStart = ipString.LastIndexOf(':');
ipString = ipString.Substring(0, portStart);

I would expect that to work with IPv6 as well, unless your IPv6 "address and port" format doesn't use a colon - as is feasible with RFC5952. Basically to do this well, you'll need to have more of an idea of the format you'll be receiving.

people

See more on this question at Stackoverflow