Files
the-way-to-go_ZH_CN/eBook/exercises/chapter_7/split_string.go
Allen.Guo 695188fe0d 修复代码bug--> exercises/chapter_7/remove_slice.go (#433)
* 修复代码bug, 切片取值错误导致结果偏差,丢失最后一个元素,优化创建切片的容量,避免每次自动扩容1个大小

* 使用切片完成操作
2018-03-05 03:54:44 -05:00

20 lines
681 B
Go
Executable File

package main
import (
"fmt"
)
func main() {
rawString := "Google"
index := 3
sp1, sp2 := splitStringbyIndex(rawString, index)
fmt.Printf("The string %s split at position %d is: %s / %s\n", rawString, index, sp1, sp2)
}
func splitStringbyIndex(str string, i int) (sp1, sp2 string) {
rawStrSlice := []byte(str)
sp1 = string(rawStrSlice[:i])
sp2 = string(rawStrSlice[i:])
return
}