|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
IPAddressHi
Is there a class with a method in the .NET Framework that will verify if a string is in the correct dotted format to be an IPAddress. Similar to inet_addr nnn.nnn.nnn.nnn Thank You Mark Mark Cooper <MarkCnoSpamAlias@newsgroup.nospam> wrote:
> Is there a class with a method in the .NET Framework that will verify if a Have you tried IPAddress.Parse?> string is in the correct dotted format to be an IPAddress. Similar to > inet_addr > > nnn.nnn.nnn.nnn -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Yes but I was hoping to check the string without having to add the overhead
of an exception. The majority of the time it will be a DNS host name not an IP address. Mark Cooper <MarkCnoSpamAlias@newsgroup.nospam> wrote:
> Yes but I was hoping to check the string without having to add the overhead When you talk about the overhead of the exception, just how many of > of an exception. The majority of the time it will be a DNS host name not an > IP address. these are you doing? See http://www.pobox.com/~skeet/csharp/exceptions.html It would be reasonably easy to hard-code a test, and feasible to do as a regular expression (the tricky bit is rejecting 300.300.300.300 but allowing 30.30.30.255 etc). The *simplest* way is probably to use IPAddress.Parse though. Whether this counts as an abuse of exceptions is a matter of taste IMO. Note that in .NET 2 you'll be able to use IPAddress.TryParse, which is much more what you're after. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too The 2.0 Platform has a TryParse for the IPAddress, and a number of other
classes as well. It doesn't throw an exception. Unfortunately, the 1.1 platform does not. -- Show quoteHide quoteHTH, Kevin Spencer Microsoft MVP ..Net Developer Big things are made up of lots of little things. "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MPG.1da78a50c198734098c830@msnews.microsoft.com... > Mark Cooper <MarkCnoSpamAlias@newsgroup.nospam> wrote: >> Yes but I was hoping to check the string without having to add the >> overhead >> of an exception. The majority of the time it will be a DNS host name not >> an >> IP address. > > When you talk about the overhead of the exception, just how many of > these are you doing? See > http://www.pobox.com/~skeet/csharp/exceptions.html > > It would be reasonably easy to hard-code a test, and feasible to do as > a regular expression (the tricky bit is rejecting 300.300.300.300 but > allowing 30.30.30.255 etc). The *simplest* way is probably to use > IPAddress.Parse though. Whether this counts as an abuse of exceptions > is a matter of taste IMO. Note that in .NET 2 you'll be able to use > IPAddress.TryParse, which is much more what you're after. > > -- > Jon Skeet - <sk***@pobox.com> > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet > If replying to the group, please do not mail me too
Other interesting topics
.NET Framework Ignores Regional Settings on WinXP
How to compare objects why Assembly.LoadFrom() function does'nt load VC++ Project exe file Speed issues with filling a list view sample databases? HOW to solve ... System.Net.WebException: Connection closed Not all images are loaded correctly programatically how to set the steps involved in enabling the ASP. how do C#.NET load VC++Project exe How does FileSystemWatcher work? |
|||||||||||||||||||||||