示例#1
0
        /// <summary>
        /// 根据空白字符分隔字符串
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">参数为 null</exception>
        public static string[] SplitByWhiteSpace(this string s)
        {
            int index = 0;

            List <string> result = new List <string>();

            while (true)
            {
                ValueSet <int, int> tuple = s.IndexOfWhiteSpace(index, s.Length - index);

                if (tuple.IsNotNull())
                {
                    int length = tuple.Value1 - index;

                    if (length > 0)
                    {
                        result.Add(s.Substring(index, length));
                    }

                    index = tuple.Value1 + tuple.Value2;
                }
                else
                {
                    int length = s.Length - index;

                    if (length > 0)
                    {
                        result.Add(s.Substring(index, length));
                    }

                    break;
                }
            }

            return(result.ToArray());
        }