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

niclelin · · 3667 次点击
`package main import ( "fmt" ) func main() { str := "13412345678" rs := "" for i, v := range str { if i > 2 && i < 7 { rs = rs + "*" } else { rs = rs + string(v) } } fmt.Println(rs) } `
#6
更多评论
``` 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