GPS文件处理(后续)——计算单词数

根据读出的每一行数据,进行按列分组(列与列之间的空格数不确定),就相当于找单词一样

  /// <summary>

        /// 把读出的每一行进行处理,得到以列为单元的数组

        /// </summary>

        /// <param name="strLine"></param>

        /// <returns></returns>

        public static List<string> findWord(string strLine)

        {

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

            char[] chararray = strLine.ToCharArray();

            #region 格式化读出的每一行

            int ii = 0; int k = 0; int j = 0; bool wordappeared = false; bool wordappearfirs = false;

            while (ii < chararray.Length)

            {

                if (chararray[ii] == ' ')

                {

                    if (wordappearfirs == true)

                        filedArray.Insert(filedArray.Count, strLine.Substring(j, k));

 

                    wordappeared = false;

                    wordappearfirs = false;

                    k = j = 0;

 

                }

                else

                {

                    k++;

                    if (wordappeared == false)

                        j = ii;//开始出现单词

                    wordappeared = true;

                    wordappearfirs = true;

                }

                ii++;

            }

            if (filedArray.Contains("N/A"))

                return null;

            else

                return filedArray;

            #endregion

        }

 

作者: 风云

出处: http://www.cnblogs.com/fengyunlishi/

本文版权归风云和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

 

posted @ 2012-10-02 23:15  风云@历史  阅读(126)  评论(0编辑  收藏  举报