题目描述
Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case).
样例说明
"the-stealth-warrior" gets converted to "theStealthWarrior"
"The_Stealth_Warrior" gets converted to "TheStealthWarrior"
题目分析
结合题目描述以及样例:将给出的字符串转换成标准的驼峰式命名。
输入字符:
- 字符串中含有"-"
- 字符串中含有"_"
- 以上两种情况都没有
返回字符:"-“或者”_"标识的字符串中,第一个不发生改变,之后每一个中间的字符的首字母均转换成大写,且标识消失。
思路:①字符串依据"-“或者”_"切割;②根据切割之后的字符修改除第一个字符之外的字符串;③返回拼接之后的字符串
代码
func ToCamelCase(s string) string{
var strArr []string
if strings.Contains(s,"-") {
strArr=strings.Split(s,"-")
}else if strings.Contains(s,"_")