Lake County .NET Users' Group Helping the .NET developers of Lake County, Illinois

All posts

A function that converts from camel case to a phrase

From Kurt Schroeder:

 

namespace Iknowtek.Utils

{

    public static class GeneralUtilities

    {

        /// <summary>

        /// will insert a space before each capital letter Kurt Schroeder 20080617

        /// Created to deal with enums

        /// example: var str  = GeneralUtilities.SpacedOutCamelCase(   Enum.GetName(typeof(BillingCycle), p.IBillingCycle),1 ));    

 

        /// </summary>

        /// <param name="str"></param>

        /// <param name="idx"></param>

        /// <returns></returns>

        public static string SpacedOutCamelCase(string str, int idx)

        {

            if (idx == str.Length)

                return str;

            if (str[idx].ToString() == str[idx].ToString().ToUpper())

                str = str.Substring(0, ++idx - 1) + " " + str.Substring(idx - 1, (str.Length - idx + 1));

            str = SpacedOutCamelCase(str, ++idx);

            return str;

        }

 

 

    }

}

 

Facebook DZone It! Digg It! StumbleUpon Technorati Del.icio.us NewsVine Reddit Blinklist Furl it!

Post a comment!