What's the simplest way to extract the last section of an IP address?
- by Jon Cage
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?