Golang - How to return last item of strings.Split() slice? Code Example

Here is the solution for "How to return last item of strings.Split() slice?" in Golang.

Golang code for How to return last item of strings.Split() slice?

package main

import (
	"fmt"
	"strings"
)

func main() {
    s := "Hello,world,Greetings"
    last := s[strings.LastIndex(s, ",")+1:]
    fmt.Println(last)
}

/*
Output:
Greetings
*/
Code by IncludeHelp, on March 4, 2023 23:41

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.