如:
~~~
str:="abcde"
if str.length<32{
//实现str的填充满32位 可以根据自己定义的值填充满
}
~~~
```
package main
import (
"fmt"
"strings"
)
func StringFormat32(raw string) string {
switch {
case len(raw) == 32:
return raw
case len(raw) > 32:
return fmt.Sprintf("%.32s",raw[:32])
case len(raw) < 32:
return fmt.Sprintf("%s%s",raw,strings.Repeat("_",32-len(raw)))
default:
/*should never meet here*/
return raw
}
}
func main() {
fmt.Println(StringFormat32("01234567890123456789012345678901"))
fmt.Println(StringFormat32("0123456789012345678901234567890123456"))
fmt.Println(StringFormat32("01234567890123456789"))
}
```
#9
更多评论