怎么获取城市区号
fengweiqiang opened this issue · 3 comments
fengweiqiang commented
怎么获取城市区号?能不能举个例子?
ttacon commented
Good question! I'll update the README too to add retrieving the city code as an example.
ttacon commented
The following should work:
num, err := libphonenumber.Parse("1234567890", "US")
if err != nil {
// Handle error appropriately.
}
natSigNumber := libphonenumber.GetNationalSignificantNumber(num)
geoCodeLength := libphonenumber.GetLengthOfGeographicalAreaCode(num)
areaCode := ""
if geoCodeLength > 0 {
areaCode = natSigNumber[0:geoCodeLength]
}
fmt.Println(areaCode)
ttacon commented
I've also update the README with this example.