Tobiq
Tobiq

Reputation: 2657

Console not writing

using System;
using System.Net;
static class Program {
    public static void Main()
    {
        WebClient wc = new WebClient();
        var proxies = wc.DownloadString(@"http://proxy-ip-list.com/download/free-proxy-list.txt");
        Console.WriteLine("http://" + proxies.Split(';')[5]);
        Console.ReadLine();
    }
}

enter image description here

I'm very much baffled...

I tried printer Char-by-Char. I tried assigning the string to a variable before writing. I've tried everything, what's going on?

Console.WriteLine("http://" + "182.255.46.123:8080"); works...

Upvotes: 0

Views: 112

Answers (3)

RK_Aus
RK_Aus

Reputation: 946

Updated answer as per your comment. You just need to Trim() to remove all white spaces from start and end.

using System;
using System.Net;

static class Program
{
    public static void Main()
    {
        WebClient wc = new WebClient();
        var proxies = wc.DownloadString(@"http://proxy-ip-list.com/download/free-proxy-list.txt");

        Console.WriteLine("http://" + proxies.Split(';')[5].Trim());

        Console.ReadLine();
    }
}

Upvotes: 0

Gean Ribeiro
Gean Ribeiro

Reputation: 1035

Try this:

using System;
using System.Text.RegularExpressions;
using System.Net;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            WebClient wc = new WebClient();
            var proxies = wc.DownloadString(@"http://proxy-ip-list.com/download/free-proxy-list.txt");
            var regex = new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}");
            var match = regex.Matches(proxies);
            Console.WriteLine("http://" + match[3].Value);
            Console.ReadLine();
        }
    }
}

Is most save in case of changes in content of the request result.

Upvotes: 0

Rufus L
Rufus L

Reputation: 37020

It's because the string being returned contains a carriage-return character at the beginning:

proxies.Split(';')[5] = " \r182.255.46.123:8080"

You can remove it like this:

Console.WriteLine("http://" + proxies.Split(';')[5].Replace("\r", "").Trim());

Upvotes: 3

Related Questions