隐藏手机中间四位数字(go语言)

niclelin · · 3677 次点击
```go func main() { var phone string phone = "13412345678" newPhone := phone[:3] + "****" + phone[6:] fmt.Println(newPhone) } ```
#7
更多评论
``` package main import ( "fmt" "strings" ) func main() { phone := "13412345678" slice := strings.Split(phone, "") str := strings.Join(slice[0:3], "") + "****" + strings.Join(slice[7:], "") fmt.Println(str) } ```
#1
`func FormatText(str string) string { if len(str) <= 10 { return str } return str[:3] + "**" + str[len(str)-4:] }`
#2