Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert lower camelCase to PascalCase in c#?

I need to convert camelcase keys to Pascal key and I got good solution from stackoverflow. But the issue is I don't know how to exclude . in conversion.

Please find the below example:

var input= "customer.presentAddress.streetName";

Expected Output is

var output= "Customer.PresentAddress.StreetName";

PlayGround : Please click here

like image 755
Prasanna Kumar J Avatar asked Nov 18 '25 16:11

Prasanna Kumar J


1 Answers

An idea to use e.g. \b\p{Ll} (demo) for matching lower word's first letter and use a callback.

string output = Regex.Replace(input, @"\b\p{Ll}", match => match.Value.ToUpper());

See this C# demo at tio.run - \b is a word boundary and \p{Ll} matches lowercase letters.

like image 167
bobble bubble Avatar answered Nov 21 '25 06:11

bobble bubble