Click here to Skip to main content
15,888,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello codeproject members.

how can i read line by line in the listbox after grabbing the text data from pastebin raw url.

When i try the code it shows the text but not line by line.

string RawUrl = "https://pastebin.com/raw/#########";

           using (WebClient client = new WebClient())
           {
               string Get = client.DownloadString(RawUrl);
               listBox2.Items.Add(Get);
           }


What I have tried:

i tried searching the net but found nothing useful that worked.
Posted
Updated 8-Dec-20 20:10pm
Comments
[no name] 8-Dec-20 22:52pm    
If you're talking about line feeds, then you'll have to split on NewLine if you want "line by line" (from one line).
Anthony Raven 8-Dec-20 23:14pm    
could you provide the example please

It's not immediately clear from your example why you're adding the result of the Get to listBox2.Items

If you wanted to 'split' the result of the Get you could do

string[] lines = Get.Split(
    new[] { "\r\n", "\r", "\n" },
    StringSplitOptions.None
);


Then you have an array of strings in lines that you'd need to add one by one to the listbox
 
Share this answer
 
If you are after the text from a website line-by-line, then you need very much more complex processing than that: website data doesn't divide lines with newlines at all, it uses a a couple of methods:
HTML
Line one<br />Line two

HTML
<p>Line one</p><p>Line two</p>

If you want to process raw data from a site, then I'd strongly suggest you start by looking at the HtmlAgilityPack - it processes HTML data and can make your job a whole load easier!
 
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