String Benchmarks in C# - Refactoring for Speed/Maintainability

后端 未结 10 1407
无人及你
无人及你 2021-02-09 21:29

I\'ve been tinkering with small functions on my own time, trying to find ways to refactor them (I recently read Martin Fowler\'s book Refactoring: Improving the Design of Ex

10条回答
  •  逝去的感伤
    2021-02-09 21:44

    The Regex versions of your solution are not equivalent in results to the original code. Perhaps the larger context of the code avoids the areas where they differ. The original code will add a space for anything that is not a lower case character. For example "This\tIsATest" would become "This \t Is A Test" in the original but "This\t Is A Test" with the Regex versions.

    (?

    Is the pattern you want for a closer match, but even then it is still ignoring issues of i18n. The following pattern should take care of that:

    (?

提交回复
热议问题