MCPcopy Create free account
hub / github.com/MengMengCode/GetRealityDomain / getDisplayWidth

Function getDisplayWidth

main.go:494–504  ·  view source on GitHub ↗

计算字符串的显示宽度(中文字符占2个宽度,英文字符占1个宽度)

(s string)

Source from the content-addressed store, hash-verified

492
493// 计算字符串的显示宽度(中文字符占2个宽度,英文字符占1个宽度)
494func getDisplayWidth(s string) int {
495 width := 0
496 for _, r := range s {
497 if r <= 127 {
498 width++ // ASCII字符占1个宽度
499 } else {
500 width += 2 // 中文字符占2个宽度
501 }
502 }
503 return width
504}
505
506// 获取整数输入
507func getIntInput() int {

Callers 1

printBoxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected