diff --git a/src/Humanizer/StringHumanizeExtensions.cs b/src/Humanizer/StringHumanizeExtensions.cs index cf4f24ead..6142cbcba 100644 --- a/src/Humanizer/StringHumanizeExtensions.cs +++ b/src/Humanizer/StringHumanizeExtensions.cs @@ -32,8 +32,19 @@ public static partial class StringHumanizeExtensions private static Regex FreestandingSpacingCharRegex() => FreestandingSpacingCharRegexField; #endif - static string FromUnderscoreDashSeparatedWords(string input) => - string.Join(" ", input.Split(['_', '-'])); + static string FromUnderscoreDashSeparatedWords(string input) + { +#if NET7_0_OR_GREATER + return string.Create(input.Length, input, (span, state) => + { + state.AsSpan().CopyTo(span); + span.Replace('_', ' '); + span.Replace('-', ' '); + }); +#else + return input.Replace('_', ' ').Replace('-', ' '); +#endif + } static string FromPascalCase(string input) { @@ -160,4 +171,4 @@ internal static unsafe string Concat(char left, CharSpan right) => internal static unsafe string Concat(CharSpan left, char right) => Concat(left, new CharSpan(&right, 1)); #endif -} \ No newline at end of file +}