Convert Dash-Separated String to camelCase via C#

前端 未结 5 1650
天涯浪人
天涯浪人 2021-01-21 20:56

I have a large XML file that contain tag names that implement the dash-separated naming convention. How can I use C# to convert the tag names to the camel case naming convention

5条回答
  •  青春惊慌失措
    2021-01-21 21:25

    string ConvertDashToCamelCase(string input)
    {
        string[] words = input.Split('-');
    
        words = words.Select(element => wordToCamelCase(element));
    
        return string.Join("", words);
    }
    
    string wordToCamelCase(string input)
    {
        return input.First().ToString().ToUpper() + input.Substring(1).ToLower();
    }
    

提交回复
热议问题