i have string like this:
package main
import "fmt"
func main() {
some := "p1k4"
for i, j := range some {
fmt.Println()
}
}
i want take each two string there should curent string then next one, next iteration should get the previous character. the output should like p1, 1k, k4, 4p.
i have tried it and still having trouble finding the answer, how should i write the code in go and get the output i want?
>Solution :
This is a simple for loop over your string with the first character appended at the back:
package main
import "fmt"
func main() {
some := "p1k4"
ns := some + string(some[0])
for i := 0; i < len(ns)-1; i++ {
fmt.Println(ns[i:i+2])
}
}