I need to trim a given IP Address to get the first 3 parts of it
Example:
"192.168.1.20" ➨ "192.168.1."
"29.6.60.241" ➨ "29.6.60."
A subnet mask is used to divide an IP address into two parts. One part identifies the host (computer), the other part identifies the network to which it belongs.
An internet protocol (IP) address allows computers to send and receive information. There are four types of IP addresses: public, private, static, and dynamic.
An IP address has two parts: the network ID, comprising the first three numbers of the address, and a host ID, the fourth number in the address.
Start IP: Type an IP address to serve as the start of the IP range that DHCP will use to assign IP addresses to all LAN devices connected to the router. End IP: Type an IP address to serve as the end of the IP range that DHCP will use to assign IP addresses to all LAN devices connected to the router.
String result = input.Substring(0, input.LastIndexOf("."));
Using String.LastIndexOf(), it should be easy.
EDIT
Using that method you can locate the last '.'. Then you need a substring up to and (apparently) incuding that '.'. Something like:
string shortened = longIP.Substring(0,longIP.LastIndexOf(".")+1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With