b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

richtextbox 添加(2)

电脑杂谈  发布时间:2016-12-28 01:01:19  来源:网络整理

在C# RichTextBox的内容内搜索文本:

重载列表

在 RichTextBox 控件的文本中搜索字符列表中某个字符的第一个实例

[C#] public int Find(char[]);

示例

[Visual Basic, C#, C++] 下面的示例在 RichTextBox 的内容中搜索在 text 参数中传递到方法的字符。如果在 RichTextBox 中找到了 text 数组的内容,则该方法返回所找到值的索引;否则,它将返回 -1。该示例假定此方法位于 Form 的类中,该窗体包含一个名为 richTextBox1 的 RichTextBox 控件和一个连接到该示例中定义的单击事件处理方法的 Button 控件(名为 button1)。

[C#]

  1. private void button1_Click(object sender, System.EventArgs e)     
  2. {     
  3.      MessageBox.Show(FindMyText(new char[]{'D','e','l','t','a'}).ToString());     
  4. }     
  5. public int FindMyText(char[] text)     
  6. {     
  7.      // Initialize the return value to false by default.     
  8.      int returnValue = -1;     
  9.      // Ensure that a search string has been specified and a valid start point.     
  10.      if (text.Length > 0)      
  11.      {     
  12.          // Obtain the location of the first character found in the control     
  13.          // that matches any of the characters in the char array.     
  14.          int indexToText = richTextBox1.Find(text);     
  15.          // Determine whether the text was found in richTextBox1.     
  16.          if(indexToText >= 0)     
  17.          {     
  18.              // Return the location of the character.     
  19.              returnValue = indexToText;     
  20.          }     
  21.      }     
  22.      return returnValue;     
  23. }   


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-23636-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...