aaronvan icon

CamelCase

aaronvan | PRO | 05/30/18 11:53:15 PM UTC | 0 ⭐ | 518 👁️ | Never ⏰ | []
C# |

1.54 KB

|

None

|

0 👍

/

0 👎

namespace CamelCase
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(CamelCase(" hello to camel case"));
            Console.ReadKey();
        }
 
        public static string CamelCase(string str)
        {
        
            string newString = "";
 
            if (str[0] == ' ')
            {
                newString += char.ToUpper(str[1]);
 
                for (int j = 2; j < str.Length; j++)
                {
 
                    if (str[j] == ' ')
                    {
                        
                        char b = str[j + 1];
                        newString += char.ToUpper(b);
                        j++;
 
                    }
                    else
                    {
                        char b = str[j];
                        newString += b;
                    }
                }
                return newString;
            }
            else
            {
                newString += char.ToUpper(str[0]);
                for (int j = 1; j < str.Length; j++)
                {
                    if (str[j] == ' ')
                    {
                        char b = str[j + 1];
                        newString += char.ToUpper(b);
                        j++;
                    }
                    else
                    {
                        char b = str[j];
                        newString += b;
                    }
                }
                return newString;
            }
        }
    }
}

Comments