"Go Split()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
1번째 줄: 1번째 줄:
==개요==
==개요==
;Split on comma or other substring
;Split on comma or other substring
<source lang='go' run>
<syntaxhighlight lang='go' run>
package main
package main


14번째 줄: 14번째 줄:
// Output: [a b c]
// Output: [a b c]
}
}
</source>
</syntaxhighlight>
<source lang='go' run>
<syntaxhighlight lang='go' run>
package main
package main


29번째 줄: 29번째 줄:
fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins"))
fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins"))
}
}
</source>
</syntaxhighlight>
<source lang='go' run>
<syntaxhighlight lang='go' run>
package main
package main


43번째 줄: 43번째 줄:
fmt.Printf("%q\n", pieces)
fmt.Printf("%q\n", pieces)
}
}
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:48 판

1 개요

Split on comma or other substring
package main

import (
	"fmt"
	"strings"
)

func main() {
	s := strings.Split("a,b,c", ",")
	fmt.Println(s)
	// Output: [a b c]
}
package main

import (
	"fmt"
	"strings"
)

func main() {
	fmt.Printf("%q\n", strings.Split("a,b,c", ","))
	fmt.Printf("%q\n", strings.Split("a man a plan a canal panama", "a "))
	fmt.Printf("%q\n", strings.Split(" xyz ", ""))
	fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins"))
}
package main

import (
	"fmt"
	"strings"
)

func main() {
	pizza := "piece1 piece2 piece3 piece4 piece5 piece6"
	pieces := strings.Split(pizza, " ")
	fmt.Printf("%q\n", pieces)
}

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}