I am new to golang and I am trying to obtain the first character of a string in an array of strings. It seems like it would be easy, but I don't know how to approach it. Here is what I have done thus far:
package main
import (
"fmt"
"os"
"strings"
)
func acronym(s string) (acr string) {
// TODO: Your code here
var arrayOfStrings []string
arrayOfStrings = strings.Split(s, " ") //split string s into an array of strings based on space delimeter " "
for _, str := range arrayOfStrings {
fmt.Println(str)
}
return acr
}
func main() {
s := "Pan Galactic Gargle Blaster"
if len(os.Args) > 1 {
s = strings.Join(os.Args, " ")
}
fmt.Println(acronym(s))
}
I want the resulting string to be PGGB I am a bit stuck as I have only looped through the array of strings, but i can't think of something like in java where one has the method/function charAt(). Thanks!