go strings包SplitAfter函数和Split函数的区别

  1. SplitAfter   分割字符串,并保存分割符
  2. Split           分割字符串,分隔符会被去掉

执行下代码就会一目了然

package main

import (
	"fmt"
	"strings"
)

func main() {
	s := "hello/world/hello/world"

	splitAfter := strings.SplitAfter(s, "/")
	split := strings.Split(s, "/")
	fmt.Println("splitAfter:", splitAfter) //[hello/ world/ hello/ world]
	fmt.Println("split:", split)           //[hello world hello world]
}

运行之后打印:

splitAfter: [hello/ world/ hello/ world]
split: [hello world hello world]

你可能感兴趣的:(go,go,strings,SplitAfter,Split)