Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machupicchubeta/10016121 to your computer and use it in GitHub Desktop.
Save machupicchubeta/10016121 to your computer and use it in GitHub Desktop.
convert snake case to camel case in c#
"foo_bar".Split(new [] {"_"}, StringSplitOptions.RemoveEmptyEntries).Select(s => char.ToUpperInvariant(s[0]) + s.Substring(1, s.Length - 1)).Aggregate(string.Empty, (s1, s2) => s1 + s2);
@xavierpena
Copy link

Thank you very much for this snippet.

Just one thing:

Pascal case is a subset of Camel Case where the first letter is capitalized.

That is, userAccount is a camel case and UserAccount is a Pascal case.

I have tested your code and it is indeed Pascal Case (which is what I wanted) and not Cammel Case. I just wanted to let you know.

Thanks again.

@shasan-cb
Copy link

Amazing!! works flawlessly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment