mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:55:35 +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 {
|
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
|
||||||
}
|
}
|
||||||
|
@@ -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
|
}
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user