Skip to content

Instantly share code, notes, and snippets.

@ChrisWay
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisWay/14a0bd57b757a3789c2a to your computer and use it in GitHub Desktop.
Save ChrisWay/14a0bd57b757a3789c2a to your computer and use it in GitHub Desktop.
Converts a string into a format that matches .NET naming conventions.
private static string ToNetNaming(string input)
{
bool wasPreviousUpper = false;
bool isNextUpper = false;
var inputArray = input.ToCharArray();
var output = input.ToCharArray();
for (int i = 0; i < inputArray.Length; i++)
{
if (i != 0) {
wasPreviousUpper = Char.IsUpper(inputArray[i - 1]);
} else {
output[0] = Char.ToUpper(input[0]);
}
if (i < inputArray.Length - 1) {
isNextUpper = Char.IsUpper(inputArray[i + 1]);
}
if (wasPreviousUpper && isNextUpper) {
output[i] = Char.ToLower(output[i]);
}
}
return new string(output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment