What's the simplest way to extract the last section of an IP address?

Posted by Jon Cage on Stack Overflow See other posts from Stack Overflow or by Jon Cage
Published on 2010-04-22T09:39:21Z Indexed on 2010/04/22 9:43 UTC
Read the original article Hit count: 160

Filed under:
|

I have an IP address which I want to grab the last chunk of as an integer. So from "192.168.1.150" I'd get 150.

This is the code I'd concocted (I'm using C++/CLI), but somehow it feels rather clunky:

String^ ipString = "192.168.1.150";
int lastDot = ipString->LastIndexOf('.');
int lastSection = int::Parse(ipString->Substring(lastDot, ipString->Length-lastDot));

Is there a simpler way of doing this?

© Stack Overflow or respective owner

Related posts about c++-cli

Related posts about text-parsing