0

I am trying to get a line foreach line in a webclient.DownloadString("pastebinsite"); but it says cannot convert type 'char' to 'string', so I add a string[] downloaded = wc.DownloadString(arac[0] + arac[1] + @"//" + arac[2] + "/raw/" + arac[3]);

that does not work because it says cannot convert type 'string' to 'string[]' I am stuck and cannot find a answer online for this.

I have tried changing types

        {
            StringBuilder sb = new StringBuilder();
            Console.WriteLine("start?");
            Console.ReadKey();
            string[] lines = File.ReadAllLines(Directory.GetCurrentDirectory() + @"\Lines.txt");
            WebClient wc = new WebClient();
            int _checked = 0;
            int _error = 0;
            foreach(string line in lines)
            {
                ++_checked;
                //Pastebin text viewer
                try
                {
                    if (line.Contains("pastebin"))
                    {
                        var arac = line.Split('/');

//ERROR LINE CANNOT CONVERT TYPE 'STRING' TO 'STRING[]' Below
                        string[] downloaded = wc.DownloadString(arac[0] + arac[1] + @"//" + arac[2] + "/raw/" + arac[3]);

                        foreach(string line2 in downloaded)
                        {
                            if (line2.Contains(":")
                                {

                                //Console.WriteLine(arac[0] + arac[1] + @"//" + arac[2] + "/raw/" + arac[3]);
                                Console.WriteLine(arac[0] + arac[1] + @"//" + arac[2] + "/raw/" + arac[3]);
                                sb.Append(downloaded);
                            }
                        }
                    }
                    else
                    {
                        //Console.WriteLine("Not valid pastebin link!");
                    }
                    Console.Title = "Checked : " + _checked;
                }
                catch(WebException ex)
                {
                    ++_error;
                    Console.WriteLine("Error: " + _error);
                }

            }
            File.WriteAllText(Directory.GetCurrentDirectory() + @"\Output " + _checked + ".txt", sb.ToString());
            Console.Clear();
            Console.WriteLine("FINISHED");
            Console.ReadKey();
        }```
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Sheng Plays
  • 31
  • 1
  • 2
  • 1
    The [`DownloadString`](https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadstring?view=netframework-4.8) method returns a `string` and you're trying to assign the result to a `string[]`. Try: `string downloaded = …` – Rufus L May 03 '19 at 00:34
  • If you want to convert the result of `DownloadString` to a `string[]`, you could split it on the newline character: `string[] lines = downloaded.Split(new[] {Environment.NewLine}, StringSplitOptions.None);` – Rufus L May 03 '19 at 00:39
  • You can't convert a string from `wc.DownloadString` to a string array (`string[] downloaded`). Change `string[] downloaded` to `string downloaded` and split this string if needed – Pavel Kovalev May 03 '19 at 00:42

1 Answers1

0

wc.DownloadString(..) returns a string and not a string[].

you need to split the string in order to get a string[]
possible solution if you need that the string[] will contain lines would be:

var stringResult = wc.DownloadString(arac[0] + arac[1] + @"//" + arac[2] + "/raw/" + arac[3]);

then one of the following:

var lines = stringResult.Split(new [] { '\r', '\n' });
var lines = Regex.Split(stringResult, "\r\n|\r|\n");
var lines = stringResult.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.None)

and finally

foreach(string line in lines) {...}