GO語言"net"包中"IP.String"類型的用法及代碼示例。
用法:
func(ip IP) String() string
String 返回 IP 地址 ip 的字符串形式。它返回 4 種形式之一:
- "<nil>", if ip has length 0 - dotted decimal ("192.0.2.1"), if ip is an IPv4 or IP4-mapped IPv6 address - IPv6 conforming to RFC 5952 ("2001:db8::1"), if ip is a valid IPv6 address - the hexadecimal form of ip, without punctuation, if no other cases apply
例子:
package main
import (
"fmt"
"net"
)
func main() {
ipv6 := net.IP{0xfc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
ipv4 := net.IPv4(10, 255, 0, 0)
fmt.Println(ipv6.String())
fmt.Println(ipv4.String())
}
輸出:
fc00:: 10.255.0.0
相關用法
- GO IP.IsPrivate用法及代碼示例
- GO IP.Equal用法及代碼示例
- GO IP.IsLinkLocalMulticast用法及代碼示例
- GO IP.IsUnspecified用法及代碼示例
- GO IP.To16用法及代碼示例
- GO IP.IsInterfaceLocalMulticast用法及代碼示例
- GO IP.IsMulticast用法及代碼示例
- GO IP.Mask用法及代碼示例
- GO IP.DefaultMask用法及代碼示例
- GO IP.IsLoopback用法及代碼示例
- GO IP.IsGlobalUnicast用法及代碼示例
- GO IP.IsLinkLocalUnicast用法及代碼示例
- GO IP用法及代碼示例
- GO IPv4Mask用法及代碼示例
- GO IPv4用法及代碼示例
- GO Itoa用法及代碼示例
- GO IsDigit用法及代碼示例
- GO IsAbs用法及代碼示例
- GO Index.Lookup用法及代碼示例
- GO IsGraphic用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 IP.String。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。