How to get the middle character from a string in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"math"
)

func main() {
	s := "abcdefg"
	
	index := int(math.Floor(float64(len(s)) / 2))
	
	fmt.Println(string(s[index]))
}


/*
run:

d

*/

 



answered Sep 10, 2024 by avibootz
...