package main
import (
"fmt"
)
func main() {
str := "somehash"
p1 := str[:4]
p2 := str[4:]
fmt.Println(p1)
fmt.Println(p2)
}
package main
import (
"fmt"
)
func min(a, b int) int {
if a < b {
return a
}
return b
}
func splitIntoChunks(s string, chunkLength int) []string {
length := len(s)
chunksCount := length / chunkLength
if length%chunkLength != 0 {
chunksCount += 1
}
chunks := make([]string, chunksCount)
for i := range chunks {
from := i * chunkLength
to := min(length, from+chunkLength)
chunks[i] = s[from:to]
}
return chunks
}
func main() {
s := "aaabbbcccdddeeee"
fmt.Println(splitIntoChunks(s, 3))
}