CroMagnon CroMagnon - 1 year ago 125
C# Question

String small replacement

I am searching for a simple way to remove underscores from strings and replacing the next character with its upper case letter.

For example:

From: "data" to: "Data"
From: "data_first" to: "DataFirst"
From: "data_first_second" to: "DataFirstSecond"

Answer Source

Who needs more than one line of code?

var output = Regex.Replace(input, "(?:^|_)($|.)", m => m.Groups[1].Value.ToUpper());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download