3 回答
TA贡献1851条经验 获得超3个赞
我以为我会在这里补充的方式剥离的字节顺序标记从序列串-而不是直接字节乱搞(如上图所示)。
package main
import (
"fmt"
"strings"
)
func main() {
s := "\uFEFF is a string that starts with a Byte Order Mark"
fmt.Printf("before: '%v' (len=%v)\n", s, len(s))
ByteOrderMarkAsString := string('\uFEFF')
if strings.HasPrefix(s, ByteOrderMarkAsString) {
fmt.Printf("Found leading Byte Order Mark sequence!\n")
s = strings.TrimPrefix(s, ByteOrderMarkAsString)
}
fmt.Printf("after: '%v' (len=%v)\n", s, len(s))
}
其他“字符串”函数也应该工作。
这是打印出来的:
before: ' is a string that starts with a Byte Order Mark (len=50)'
Found leading Byte Order Mark sequence!
after: ' is a string that starts with a Byte Order Mark (len=47)'
干杯!
- 3 回答
- 0 关注
- 377 浏览
添加回答
举报