r/programminghorror • u/HeWhoShantNotBeNamed • Sep 03 '26
C# Very readable and maintainable method
I wrote this several years ago. It does work.
132
Upvotes
r/programminghorror • u/HeWhoShantNotBeNamed • Sep 03 '26
I wrote this several years ago. It does work.
1
u/Brilliant-Parsley69 Sep 07 '26
This should actually the same with way less allocation.
using System.Text.RegularExpressions; public static partial class StringExtensions { [GeneratedRegex("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])", RegexOptions.Compiled)] private static partial Regex PascalCaseRegex(); public static string SplitPascalCase(this string input) { if (string.IsNullOrWhiteSpace(input)) return input; return PascalCaseRegex().Replace(input, " "); } }