a := "你好,世界!" // 包含中文字符的字符串
a1 := string([]rune(a)[:4])
b := "你" // 包含中文字符的字符串
b1 := string([]rune(b)[:6])
c := "hello" // 包含中文字符的字符串
c1 := string([]rune(c)[:6])
GOlang截取字符串
于 2023-10-23 18:57:09 首次发布
a := "你好,世界!" // 包含中文字符的字符串
a1 := string([]rune(a)[:4])
b := "你" // 包含中文字符的字符串
b1 := string([]rune(b)[:6])
c := "hello" // 包含中文字符的字符串
c1 := string([]rune(c)[:6])