题目
引自codewars:
Write a function to convert a name into initials. This kata strictly takes two words with one space in between them.
The output should be two capital letters with a dot seperating them.
It should look like this:
Sam Harris => S.H
Patrick Feeney => P.F
分析
略
实现
package kata
import "strings"
func AbbrevName(name string) string{
s := strings.Split(name, " ")
return strings.ToUpper(string(s[0][0])) + "." + strings.ToUpper(string(s[1][0])) // Note 1
}
注1: 字符串索引取值类型为byte,需要强制转换为string类型。