-
-
Save digitalconceptvisuals/7328c15cfa90c4dc18d5a479d8c2808b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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