Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement