Get a specific octet from the string representation of an IPv4 address
问题 I have a variable named $Ip . This variable has an IP inside like "172.13.23.34". I would like to get the 3rd octet or the next character between 172.13. and .34 which is a string number 23 in this case and store in another variable to set up a VLANID with the command below. $Ip = 172.13.23.34 $VLANID = ? Set-Netadapter -Name "Ethernet" -VlanID $VLANID How can I get this specific information? 回答1: While -split, the regex-based string-splitting operator , or the literal-substring-based Split()