Go 语言:如何将字符串前几位替换为星号
你可以使用 strings.Replace 函数来将字符串的前几位替换为 ****。
下面是一个示例代码:
package main
import (
"fmt"
"strings"
)
func main() {
str := "Hello, World!"
replaced := "****" + str[4:]
fmt.Println(replaced)
}
输出结果为:****o, World!
原文地址: https://www.cveoy.top/t/topic/pkVL 著作权归作者所有。请勿转载和采集!