Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Text;
class Evil
{
string changeCase(string caseType, params string[] words)
{
// Sanitize the input
caseType = caseType.Trim().ToLower();
// Accumulate result in StringBuilder
var result = new StringBuilder();
// We currently support lower and camel case
if (caseType == "lower")
{
// Every word is converted to lower
// And concatenated
foreach (var word in words)
{
result.Append(
word
.Trim()
.ToLower());
}
}
else if (caseType == "camel")
{
// First word is lower
result.Append(
words[0]
.Trim()
.ToLower()
);
// Subsequent words are Proper case
for (var offset = 1;
offset < words.Length;
offset++)
{
// First letter is uppercase
result.Append(
words[offset]
.Substring(0, 1)
.ToUpper());
// Rest of the letters are lowercase
result.Append(
words[offset].
Substring(1).
ToLower());
}
}
return result.ToString();
}
static void Main(string[] args)
{
Evil obj = new Evil();
Console.WriteLine(obj.changeCase("camel", "Two", "Words"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment