我需要将驼峰式 key 转换为 Pascal key ,我从 stackoverflow 得到了很好的解决方案.
但问题是我不知道如何在转换中排除 .
。
请看下面的例子:
var input= "customer.presentAddress.streetName";
预期输出是
var output= "Customer.PresentAddress.StreetName";
Playground :Please click here
最佳答案
一个想法使用例如\b\p{Ll}
(demo)用于匹配较低单词的第一个字母和 use a callback .
string output = Regex.Replace(input, @"\b\p{Ll}", match => match.Value.ToUpper());
See this C# demo at tio.run - \b
是 word boundary和 \p{Ll}
matches 小写字母。
https://stackoverflow.com/questions/74069525/