在Rich_Text_Box中找到 [英] find in Rich_Text_Box
问题描述
我有一个Rich_textbox和两个text_box和一个按钮,当我在rich_textbox中写任何东西并在text_box1中写一个词并单击button时,我想在rich_textbox中找到该词.
并在找到它时替换掉text_box2中的文本
请帮助.
对不起我的英语
Hi,
i have a Rich_textbox and two text_box and a button, i want when i write any thing in rich_textbox and write a word in text_box1 and click button, find the word in rich_textbox.
and when find it replace whit the text in text_box2
plz help.
sorry for my english
推荐答案
查找文本
for Find text
私有无效按钮1_Click(对象发送者,EventArgs e)
{
字符串str = richTextBox1.Text;
如果(str.Contains(textBox1.Text))
{
label1.Text =真";
}
其他
{
label1.Text ="False";
}
}
private void button1_Click(object sender, EventArgs e)
{
string str = richTextBox1.Text;
if (str.Contains(textBox1.Text))
{
label1.Text = "True";
}
else
{
label1.Text = "False";
}
}
用于替换文字
str.Replace(Textbox1.text,textbox2.text)
希望这段代码对您有所帮助
问候
假
:)
for replace text
str.Replace(Textbox1.text,textbox2.text)
I hope This code really help u
Regard
Sham
:)
您应该将此代码用于按钮的事件处理程序:
You should use this code for the event handler of the button:
private void button1_Click(object sender, EventArgs e)
{
string strTextToFind = TextBox1.Text;
string strTextToReplace = textBox2.Text;
richTextBox1.Text.Replace(strTextToFind, strTextToReplace);
}
基本上,String.Replace方法搜索字符串(strTextToFind),并在找到该字符串时将其替换为另一个字符串(strTextToReplace).
Basically the String.Replace method searches for the string (strTextToFind) and when it finds it, it replaces it with another string (strTextToReplace).
阿米尔,
请在您的按钮单击事件方法中添加以下代码.
字符串str1 = RichTextbox.Text;
int loc = str1.IndexOf(TextBox1.Text);
if(loc == -1)
{
返回;
}
其他
{
str1.replace(Textbox1.Text,Textbox2.Text)
}
RichTextBox.Text = str1;
Hi Amir,
Please add below code in your button click event method.
string str1= RichTextbox.Text;
int loc = str1.IndexOf(TextBox1.Text);
if(loc == -1)
{
return;
}
else
{
str1.replace(Textbox1.Text, Textbox2.Text)
}
RichTextBox.Text = str1;
这篇关于在Rich_Text_Box中找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!