且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当传入的参数值来自Function时,没有记录返回

更新时间:2023-11-30 22:45:22

可以用一行重新编写用单个空格替换空格序列的函数:

Your function that replaces sequences of spaces with a single space can be re-written in a single line:

string.Join(" ", xString.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);

如果要使其成为扩展方法,则可以这样进行:

If you would like to make it an extension method, you can do it like this:

static class StringExtensions {
    public static string RemoveExtraSpaces(this string xString) {
        return string.Join(" ", xString.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries));
    }
}