10 examples of 'golang split string by comma' in Go

Every line of 'golang split string by comma' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
425func splitUnescapedComma(str string) []string {
426 var ret []string
427 indexes := sepPattern.FindAllStringIndex(str, -1)
428 last := 0
429 for _, is := range indexes {
430 ret = append(ret, str[last:is[1]-1])
431 last = is[1]
432 }
433 ret = append(ret, str[last:])
434 return ret
435}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

506func splitArray(val string) []string{
507 if val == "" || val == "0"{
508 return []string{}
509 }
510 return strings.Split(val, ARRAY_SPLIT)
511}
49func SplitClean(s string, sep string) []string {
50 if s == "" {
51 return []string{}
52 }
53 bb := strings.Split(s, sep)
54 var r []string
55 for _, str := range bb {
56 if str != "" {
57 r = append(r, strings.TrimSpace(str))
58 }
59 }
60 return r
61}
190func splitString(_ RideEnvironment, args ...rideType) (rideType, error) {
191 s1, s2, err := twoStringsArgs(args)
192 if err != nil {
193 return nil, errors.Wrap(err, "splitString")
194 }
195 r := make(rideList, 0)
196 for _, p := range strings.Split(s1, s2) {
197 r = append(r, rideString(p))
198 }
199 return r, nil
200}
22func Split2(str string, sep string) (string, string) {
23 splitIdx := strings.Index(str, sep)
24 if splitIdx == -1 {
25 return str, ""
26 }
27 return str[:splitIdx], str[splitIdx+len(sep):]
28}
149func split(str string) (words []string) {
150 repl := strings.NewReplacer(
151 "@", "At ",
152 "&", "And ",
153 "|", "Pipe ",
154 "$", "Dollar ",
155 "!", "Bang ",
156 "-", " ",
157 "_", " ",
158 )
159
160 rex1 := regexp.MustCompile(`(\p{Lu})`)
161 rex2 := regexp.MustCompile(`(\pL|\pM|\pN|\p{Pc})+`)
162
163 str = trim(str)
164
165 // Convert dash and underscore to spaces
166 str = repl.Replace(str)
167
168 // Split when uppercase is found (needed for Snake)
169 str = rex1.ReplaceAllString(str, " $1")
170
171 // check if consecutive single char things make up an initialism
172 once.Do(sortInitialisms)
173 for _, k := range initialisms {
174 str = strings.Replace(str, rex1.ReplaceAllString(k, " $1"), " "+k, -1)
175 }
176 // Get the final list of words
177 words = rex2.FindAllString(str, -1)
178
179 return
180}
15func SplitStrN(s string, sep string, n int) []string {
16 return strings.SplitN(s, sep, n)
17}
30func SplitString(str string) []string {
31 if len(str) == 0 {
32 return []string{}
33 }
34
35 return regexp.MustCompile("[, ]+").Split(str, -1)
36}
115func Strings_Split(Data string, Split string) []string {
116 return strings.Split(Data, Split)
117}
57func SplitInTwo(s, sep string) (string, string) {
58 if !strings.Contains(s, sep) {
59 log.Fatal(s, "does not contain", sep)
60 }
61 split := strings.Split(s, sep)
62 return split[0], split[1]
63}

Related snippets