Last active
August 29, 2015 14:24
-
-
Save ChrisWay/14a0bd57b757a3789c2a to your computer and use it in GitHub Desktop.
Converts a string into a format that matches .NET naming conventions.
This file contains hidden or 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
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