Best way to convert Pascal Case to a sentence

后端 未结 16 1958
天命终不由人
天命终不由人 2020-12-08 13:00

What is the best way to convert from Pascal Case (upper Camel Case) to a sentence.

For example starting with

\"AwaitingFeedback\"

a

16条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 13:19

    I will prefer to use Humanizer for this. Humanizer is a Portable Class Library that meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities.

    Short Answer

    "AwaitingFeedback".Humanize() => Awaiting feedback
    

    Long and Descriptive Answer

    Humanizer can do a lot more work other examples are:

    "PascalCaseInputStringIsTurnedIntoSentence".Humanize() => "Pascal case input string is turned into sentence"
    "Underscored_input_string_is_turned_into_sentence".Humanize() => "Underscored input string is turned into sentence"
    "Can_return_title_Case".Humanize(LetterCasing.Title) => "Can Return Title Case"
    "CanReturnLowerCase".Humanize(LetterCasing.LowerCase) => "can return lower case"
    

    Complete code is :

    using Humanizer;
    using static System.Console;
    
    namespace HumanizerConsoleApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                WriteLine("AwaitingFeedback".Humanize());
                WriteLine("PascalCaseInputStringIsTurnedIntoSentence".Humanize());
                WriteLine("Underscored_input_string_is_turned_into_sentence".Humanize());
                WriteLine("Can_return_title_Case".Humanize(LetterCasing.Title));
                WriteLine("CanReturnLowerCase".Humanize(LetterCasing.LowerCase));
            }
        }
    }
    

    Output

    Awaiting feedback

    Pascal case input string is turned into sentence

    Underscored input string is turned into sentence Can Return Title Case

    can return lower case

    If you prefer to write your own C# code you can achieve this by writing some C# code stuff as answered by others already.

提交回复
热议问题