Best way to convert Pascal Case to a sentence

后端 未结 16 1948
天命终不由人
天命终不由人 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:33

    Here you go...

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace CamelCaseToString
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine(CamelCaseToString("ThisIsYourMasterCallingYou"));   
            }
    
            private static string CamelCaseToString(string str)
            {
                if (str == null || str.Length == 0)
                    return null;
    
                StringBuilder retVal = new StringBuilder(32);
    
                retVal.Append(char.ToUpper(str[0]));
                for (int i = 1; i < str.Length; i++ )
                {
                    if (char.IsLower(str[i]))
                    {
                        retVal.Append(str[i]);
                    }
                    else
                    {
                        retVal.Append(" ");
                        retVal.Append(char.ToLower(str[i]));
                    }
                }
    
                return retVal.ToString();
            }
        }
    }
    

提交回复
热议问题