How to split a string into a slice by separator in Go

2 Answers

0 votes
package main
 
import (
    "fmt"
    "strings"
)
 
func main() {
    s := strings.Split("a,b,c,d", ",")
    
    fmt.Printf("%q", s)
}
 
 
 
/*
run:
  
["a" "b" "c" "d"]
  
*/

 



answered Aug 20, 2020 by avibootz
0 votes
package main
 
import (
    "fmt"
    "strings"
)
 
func main() {
    s := strings.Split(" abc ", "")
    
    fmt.Printf("%q", s)
}
 
 
 
/*
run:
  
[" " "a" "b" "c" " "]
  
*/

 



answered Aug 20, 2020 by avibootz

Related questions

1 answer 199 views
1 answer 143 views
3 answers 305 views
305 views asked May 25, 2020 by avibootz
...