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

(새 문서: ==개요== ;Split on comma or other substring <source lang='go' run> package main import ( "fmt" "strings" ) func main() { s := strings.Split("a,b,c", ",") fmt.Println(s) // Ou...)
 
 
(사용자 2명의 중간 판 14개는 보이지 않습니다)
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


11번째 줄: 11번째 줄:
func main() {
func main() {
s := strings.Split("a,b,c", ",")
s := strings.Split("a,b,c", ",")
fmt.Println(s)
fmt.Println(s)         // [a b c]
// Output: [a b c]
fmt.Printf("%#v\n", s) // []string{"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>
<syntaxhighlight lang='go' run>
package main
 
import (
"fmt"
"strings"
)


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


==같이 보기==
==같이 보기==
* [[Go Join()]]
* [[Go SplitN()]]
* [[Go SplitN()]]
* [[Go SplitAfter()]]
* [[Go SplitAfter()]]
* [[Go SplitAfterN()]]
* [[Go SplitAfterN()]]
* [[Go Fields()]]
* [[Go 정규표현식으로 문자열 분할]]
* [[함수 explode()]]


==참고==
==참고==
41번째 줄: 58번째 줄:
* https://yourbasic.org/golang/split-string-into-slice/
* https://yourbasic.org/golang/split-string-into-slice/


[[분류: Go strings]]
[[분류: Go 문자열]]
[[분류: Go strings 패키지]]

2023년 4월 25일 (화) 18:11 기준 최신판

1 개요[ | ]

Split on comma or other substring
package main

import (
	"fmt"
	"strings"
)

func main() {
	s := strings.Split("a,b,c", ",")
	fmt.Println(s)         // [a b c]
	fmt.Printf("%#v\n", s) // []string{"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 }}