getDisplayWidth 计算字符串的显示宽度(中文字符占2个位置)
(s string)
| 117 | |
| 118 | // getDisplayWidth 计算字符串的显示宽度(中文字符占2个位置) |
| 119 | func getDisplayWidth(s string) int { |
| 120 | width := 0 |
| 121 | for _, r := range s { |
| 122 | if r < 128 { |
| 123 | // ASCII字符占1个位置 |
| 124 | width++ |
| 125 | } else { |
| 126 | // 中文字符占2个位置 |
| 127 | width += 2 |
| 128 | } |
| 129 | } |
| 130 | return width |
| 131 | } |
| 132 | |
| 133 | // PrintAdvertisement 打印广告信息 |
| 134 | func PrintAdvertisement() { |