Camel Case Conversion in C#
Let's start by creating a C# program that takes a regular string and converts it to Camel Case. We will use a simple approach, breaking the string into words, capitalizing the initial letter of each word (except the first), and then concatenating them back together.
using System;
class Program
{
static string ConvertToCamelCase(string input)
{
string[] words = input.Split(' ');
for (int i = 1; i < words.Length; i++)
{
words[i] = char.ToUpper(words[i][0]) + words[i].Substring(1);
}
return string.Join("", words);
}
static void Main()
{
string inputString = "convert strings to camel case";
string camelCaseResult = ConvertToCamelCase(inputString);
Console.WriteLine("Original String: " + inputString);
Console.WriteLine("Camel Case Output: " + camelCaseResult);
}
}
Output:
Let's run the program with the example string "convert strings to camel case" and examine the output:
Original String: convert strings to camel case
Camel Case Output: convertStringsToCamelCase
Comments (0)