mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 22:06:51 +08:00
Changes to these two files seem not necessary.
This reverts commit 695188fe0d
.
This commit is contained in:
@@ -12,8 +12,8 @@ func main() {
|
||||
}
|
||||
|
||||
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])
|
||||
copy(result[at:], slice[end+1:])
|
||||
copy(result[at:], slice[end:])
|
||||
return result
|
||||
}
|
||||
|
@@ -1,19 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
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)
|
||||
str := "Google"
|
||||
for i := 0; i <= len(str); i++ {
|
||||
a, b := Split(str, i)
|
||||
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])
|
||||
sp2 = string(rawStrSlice[i:])
|
||||
return
|
||||
}
|
||||
|
||||
func Split(s string, pos int) (string, string) {
|
||||
return s[0:pos], s[pos:]
|
||||
}
|
||||
|
Reference in New Issue
Block a user