Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->编程语言 ->ASP.NET ->正文

老外编的程序(九):Using Indexer Properties

来源:Linuxdby.com 作者:Webmaster 时间:2007-04-28 点击: [收藏] [投稿]
// indexedproperty.cs
using System;

public class Document
{
    // Type allowing the document to be viewed like an array of words:
    public class WordCollection
    {
        readonly Document document;  // The containing document

        internal WordCollection(Document d)
        {
           document = d;
        }

        // Helper function -- search character array "text", starting at
        // character "begin", for word number "wordCount." Returns false
        // if there are less than wordCount words. Sets "start" and
        // length" to the position and length of the word within text:


        private bool GetWord(char[] text, int begin, int wordCount,
                                       out int start, out int length)
        {
            int end = text.Length;
            int count = 0;
            int inWord = -1;
            start = length = 0;

            for (int i = begin; i <= end; ++i)
            {
                bool isLetter = i < end && Char.IsLetterOrDigit(text[i]);

                if (inWord >= 0)
                {
                    if (!isLetter)
                    {
                        if (count++ == wordCount)
                        {
                            start = inWord;
                            length = i - inWord;


                            return true;
                        }
                        inWord = -1;
                    }
                }
                else
                {
                    if (isLetter)
                        inWord = i;
                }
            }
            return false;
        }

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:续(这个例子是针对ACCESS的更新、删除、还有定位的,希望能对你有所帮助)   下一篇:Passport 你的网站(在你的WebSite上实现MS Passport )上

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号