I know about ToUpper and ToLower from strings package but obviously they won't help here. Is there a built-in function or do I have to write one myself?
1条回答 默认 最新
- dongtang1966 2016-07-06 21:34关注
You need to write one yourself, but the building blocks are already in the standard library:
func swapCase(s string) string { return strings.Map(func(r rune) rune { switch { case unicode.IsLower(r): return unicode.ToUpper(r) case unicode.IsUpper(r): return unicode.ToLower(r) } return r }, s) }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报