So, I'm attempting to make a program that searches online for a file, downloads it, then in the file that is downloaded has like something like this:

None Yet!
(Sorry, but there is nothing yet!)

Then on the right of the listbox there is a richtextbox that I want what is in ( and ) to show there.

FileInfo file = new FileInfo("C:\\available.txt");
                StreamReader stRead = file.OpenText();
                while (!stRead.EndOfStream)
                {
                    listBox3.Items.Add(stRead.ReadLine());
                }

I want the code to hide whats in ( and ) and what ever that is in ( and ) to show in the richtextbox.

Recommended Answers

All 3 Replies

Well...

You could try parsing your stream using .Split('(',')') assuming every line has content within brackets as such:
main content details(secondary content details)

You would get a result where your string array's even values were your listbox items and it's odd values would be the richtext values.

This could be potentially achieved by:

FileInfo file = new FileInfo("C:\\available.txt");
StreamReader stRead = file.OpenText();
string readerRaw = "";
while (!stRead.EndOfStream)
    {
        readerRaw += (stRead.ReadLine());
    }
string[] readerParsed = readerRaw.Split('(',')');
for int (a = 0; a < readerParsed.Length; a++)
{
    if (a == 0 || (a % 2) == 0)
    {
        listBox3.Items.Add(readerParsed[a]);
    }
    else
    {
        ---insert logic to add readerParsed[a] to richtextbox for all odd values of a
    }
}

At least I think that would work, and again it depends on EACH line of the file being read to be in the format provided above the example.

Awesome, but too long. I'm going to use a different symbol,

private void btnLoad_Click(object sender, EventArgs e)
        {
            foreach (string s in getPageSource("http://www.artilleryhacks.com/ca/pub/combatarms_available.txt").Split('\n'))
            {
                lstName.Items.Add(s.Split('§')[0]);
                descriptions.Add(s.Split('§')[1]);
            }
        }

        string getPageSource(string URL)
        {
            System.Net.WebClient webClient = new System.Net.WebClient();
            string strSource = webClient.DownloadString(URL);
            webClient.Dispose();
            return strSource;
        }

        private void lstName_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtDescription.Text = descriptions[lstName.SelectedIndex];
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtDescription.Text = "";
            lstName.Items.Clear();
        }

Whichever works for you, as I said it's just a matter of parsing by one value to get results 0 and 1 and using those to fill your data destinations.

Don't forget to mark the thread solved when you're done :) Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.