C#获取某一字符串第N到第N+1空格的字符

/// <summary>
        /// 获取某一字符串第N到第N+1空格的字符
        /// </summary>
        /// <returns></returns>
        public static Func<int, int, string, string, string> GetStrOfStringInBlankIndex()
        {
            return (x, y, z, f) =>
            {
                int start = GetBlankIndexOfString()(x, z, f);
                int end = GetBlankIndexOfString()(y, z, f);
                string str = f.Substring(start, end - start);
                return str;
            };
        }

        /// <summary>
        /// 获取第N个空格所在
        /// </summary>
        /// <returns></returns>
        public static Func<int, string, string, int> GetBlankIndexOfString()
        {
            return (x, y, z) =>
            {
                int result = 0, index = 0;
                string str = z;
                for (int i = 0; i < x; i++)
                {
                    index = str.IndexOf(y);
                    str = str.Substring(index, str.Length - index).TrimStart();
                    result = z.LastIndexOf(str);
                }
                return result;
            };
        }

调用方式 

string y="1 2 3 4 5";
GetStrOfStringInBlankIndex()(3, 4, "  ", y).Trim()
原文地址:https://www.cnblogs.com/CityOfThousandFires/p/13753427.html