Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi For my application, I need a code that searches for Listbox text that has the beginning and end characters

code for open text to listbox

Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "txt files (*.php)|*.php|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            textBox1.Text = File.ReadAllText(openFileDialog1.FileName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }

Listbox will have text

for example

text text text

<-- text to be deleted

text to be deleted

text to be deleted ->

text text text

.......................................

the program will delete everything written in <- -> and so it will stay

text text text

text text text

Thank you

What I have tried:

I tried to write two indexes but this was not me mainly this can only search one character but I have more.
I open the text in the listbox but here I do not know how to delete the text that searches for the characters and deletes the text between them.
I used the string but this could only search me for the <- characters and deleted one line, which is wrong.
it must look for the text between <- and -> and delete everything in between
Posted
Updated 8-Sep-19 3:13am

Quote:
I tried to write two indexes but this was not me mainly this can only search one character but I have more.

Since when?
string input = "The beginning <-- The middle --> The end";
int start = input.IndexOf("<--");
int end = input.IndexOf("-->");
Console.WriteLine($"Start = {start}, end = {end}");
 
Share this answer
 
I need to read the text from Listbox and then search for the lyrics by word and delete them
maybe something like that
  for (int n = listBox1.Items.Count - 1; n> = 0; --n)
{
   string s = listBox1.Items [n] .ToString ();
             {
                 int start = n. IndexOf ("<-");
                 int end = n.IndexOf ("->");
                 {
                     listBox1.Items.Remove (s);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900