Example #1
0
        //统计单词个数
        public int Countwords(string str)
        {
            IsWord isWord = new IsWord();
            int    count  = 0;
            int    i;

            string[] sArray = str.Split(new string[2] {
                " ", "\r\n"
            }, StringSplitOptions.None);
            for (i = 0; i < sArray.Length; i++)
            {
                if (sArray[i].Length != 0 && isWord.Isword(sArray[i]))
                {
                    count++;
                }
            }
            return(count);
        }
Example #2
0
        //存取所有单词
        public string[] Getwords(string str)
        {
            IsWord isWord = new IsWord();

            string[] words = new string[Countwords(str)];//用于存放单词
            int      i, j;

            //string[] sArray = str.Split(new char[2] {' ','\n' });
            string[] sArray = str.Split(new string[2] {
                " ", "\r\n"
            }, StringSplitOptions.None);
            for (i = 0, j = 0; i < sArray.Length; i++)
            {
                if (sArray[i].Length != 0 && isWord.Isword(sArray[i]))
                {
                    words[j] = sArray[i];
                    j++;
                }
            }
            return(words);
        }