Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1.6 字符串 JOIN 函数, 实现方法已经修改 #52

Open
tan00 opened this issue Oct 22, 2018 · 0 comments
Open

2.1.6 字符串 JOIN 函数, 实现方法已经修改 #52

tan00 opened this issue Oct 22, 2018 · 0 comments

Comments

@tan00
Copy link

tan00 commented Oct 22, 2018

关于join函数的说明, 可能需要修改

标准库的实现没有用 bytes 包,当然也不会简单的通过 + 号连接字符串

目前查看标准库实现方式是使用了 += 字符串连接操作的.

func Join(a []string, sep string) string {
	switch len(a) {
	case 0:
		return ""
	case 1:
		return a[0]
	case 2:
		// Special case for common small values.
		// Remove if golang.org/issue/6714 is fixed
		return a[0] + sep + a[1]
	case 3:
		// Special case for common small values.
		// Remove if golang.org/issue/6714 is fixed
		return a[0] + sep + a[1] + sep + a[2]
	}
        ...
$ go version
go version go1.10 windows/amd64

该版本也没有引入 bytes 包. 但直接使用了 += 连接符

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant