How to split a string at the first occurrence of a separator in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"strings"
)

func main() {
	s := "Go, Java, C++"
	sep := ","

	// func Cut(s, sep string) (before, after string, found bool)
	before, after, found := strings.Cut(s, sep)

	fmt.Printf("before = %q, after = %q, found = %v\n", before, after, found)
}



/*
run:

before = "Go", after = " Java, C++", found = true

*/

 



answered Aug 25, 2024 by avibootz

Related questions

...