string.IndexOf help

G

Guest

In my project I want to search thru a text in a text box or RichTextBox.

When I search I want to list all lines that contain the string I am
searching for.

e.g.

one plus four
two plus four
three plus four
one minus four
one divided by four
two minus four
two divided by four
three plus five
three minus five

search for the string "one", and display the contents of all lines in the
TextBox/RichTextBox.

I envision that the TextBox/RichTextBox would be a control that is hidden
normally and then the search form would resize and show the
TextBox/RichTextBox control with the results.

Could someone please post a sample?

Thanks,

Brian
 
R

rammer

Hello, Brian

so what exactly are you looking for? example of searching that
richtextbox or resizing form?
im sure nobody has the will to make programs for you but surely
someone may help if you have precise questions.

sorry for my english:p
 
G

Guest

Hi,
I think you are looking for something like below:
static int previndex;
private void button1_Click(object sender, System.EventArgs e)
{
for(int lineno = 0;lineno < richTextBox1.Lines.GetLength(0);lineno++)
{
previndex = richTextBox1.Find("one",previndex,RichTextBoxFinds.WholeWord
);
int richtextboxlineno =
richTextBox1.GetLineFromCharIndex(richTextBox1.Find("one",previndex,RichTextBoxFinds.WholeWord ));
if (previndex ==0 )
{
previndex++;
}
richTextBox2.AppendText(richTextBox1.Lines[richtextboxlineno]);
}
}
 
G

Guest

Hi Rammer, I am looking for a sample/snipit of how to utilize the IndexOf
method that makes better sense than the ones on the MSDN Library.

I am just not grasping that one.
 
G

Guest

Manish that example I think will meet the needs and educates me further.

I will substitue the fixed string into a variable, so that I can search for
different stuff.

I appreciate the example.

Many Thanks,




Manish Bafna said:
Hi,
I think you are looking for something like below:
static int previndex;
private void button1_Click(object sender, System.EventArgs e)
{
for(int lineno = 0;lineno < richTextBox1.Lines.GetLength(0);lineno++)
{
previndex = richTextBox1.Find("one",previndex,RichTextBoxFinds.WholeWord
);
int richtextboxlineno =
richTextBox1.GetLineFromCharIndex(richTextBox1.Find("one",previndex,RichTextBoxFinds.WholeWord ));
if (previndex ==0 )
{
previndex++;
}
richTextBox2.AppendText(richTextBox1.Lines[richtextboxlineno]);
}
}
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



Brian Cook said:
In my project I want to search thru a text in a text box or RichTextBox.

When I search I want to list all lines that contain the string I am
searching for.

e.g.

one plus four
two plus four
three plus four
one minus four
one divided by four
two minus four
two divided by four
three plus five
three minus five

search for the string "one", and display the contents of all lines in the
TextBox/RichTextBox.

I envision that the TextBox/RichTextBox would be a control that is hidden
normally and then the search form would resize and show the
TextBox/RichTextBox control with the results.

Could someone please post a sample?

Thanks,

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top