1 개요[ | ]
- Go padStart()
Go
CPU
-1.0s
MEM
-0M
-1.0s
Copy
package main
import (
"fmt"
"strings"
)
func padStart(s string, n int, fill string) string {
fillsize := n - len(s)
if fillsize < 1 {
return s
}
return strings.Repeat(fill, fillsize) + s
}
func main() {
s := "Hello"
fmt.Println(padStart(s, 8, "*"))
words := []string{"a", "bee", "hello", "playground"}
for _, word := range words {
fmt.Println(padStart(word, 5, "_"))
}
}
***Hello ____a __bee hello playground
2 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.