How to get the first word from a string in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"strings"
)

func main() {
	s := "go javascript php c c++ python"

	fmt.Println(s[:strings.Index(s, " ")])
}


/*
run:

go

*/

 



answered Sep 19, 2024 by avibootz
...