Revert "修复代码bug--> exercises/chapter_7/remove_slice.go (#433)" (#757)

Changes to these two files seem not necessary.

This reverts commit 695188fe0d.
This commit is contained in:
TalonsLee
2020-02-01 22:42:01 +08:00
committed by GitHub
parent 7034c2cd49
commit 7a12625ff5
2 changed files with 14 additions and 17 deletions

View File

@@ -12,8 +12,8 @@ func main() {
} }
func RemoveStringSlice(slice []string, start, end int) []string { func RemoveStringSlice(slice []string, start, end int) []string {
result := make([]string, len(slice)-(end-start)-1) result := make([]string, len(slice)-(end-start))
at := copy(result, slice[:start]) at := copy(result, slice[:start])
copy(result[at:], slice[end+1:]) copy(result[at:], slice[end:])
return result return result
} }

View File

@@ -1,19 +1,16 @@
package main package main
import ( import "fmt"
"fmt"
)
func main() { func main() {
rawString := "Google" str := "Google"
index := 3 for i := 0; i <= len(str); i++ {
sp1, sp2 := splitStringbyIndex(rawString, index) a, b := Split(str, i)
fmt.Printf("The string %s split at position %d is: %s / %s\n", rawString, index, sp1, sp2) fmt.Printf("The string %s split at position %d is: %s / %s\n", str, i, a, b)
} }
func splitStringbyIndex(str string, i int) (sp1, sp2 string) { }
rawStrSlice := []byte(str)
sp1 = string(rawStrSlice[:i]) func Split(s string, pos int) (string, string) {
sp2 = string(rawStrSlice[i:]) return s[0:pos], s[pos:]
return
} }