Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Func<String, String> x = name => {
var buf = new StringBuilder();
for (var i = 0; i < name.Length; ++i) {
var prev = i == 0 ? '\0' : name[i - 1];
var curr = name[i];
var next = i == name.Length - 1 ? '\0' : name[i + 1];
if (Char.IsLower(prev) && Char.IsUpper(curr) && !Char.IsUpper(next)) {
buf.Append("-");
buf.Append(Char.ToLower(curr));
} else {
buf.Append(curr);
}
}
return buf.ToString();
};
x("test").Dump(); // prints "test"
x("compileTest").Dump(); // prints "compile-test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment