Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: What's an efficient way of parsing a string with one delimiter through ReadLine() of TextReader?

Tags:

c#

split

listview

C#: What's an efficient way to parse a string with one delimiter for each ReadLine() of TextReader?

My objective is to load a list of proxies to ListView into two columns (Proxy|Port) reading from a .txt file. How would I go upon splitting each readline() into the proxy and port variables with the delimiter ":"?

This is what I've got so far,

    public void loadProxies(string FilePath)
    {
        string Proxy; // example/temporary place holders
        int Port; // updated at each readline() loop.

        using (TextReader textReader = new StreamReader(FilePath))
        {
            string Line;
            while ((Line = textReader.ReadLine()) != null)
            {
                // How would I go about directing which string to return whether
                // what's to the left of the delimiter : or to the right?
                //Proxy = Line.Split(':');
                //Port = Line.Split(':');

                // listview stuff done here (this part I'm familiar with already)
            }
        }
    }

If not, is there a more efficient way to do this?

like image 593
Michael Irvin Avatar asked Mar 04 '10 23:03

Michael Irvin


1 Answers

string [] parts = line.Split(':');
string proxy = parts[0];
string port = parts[1];
like image 147
Ta01 Avatar answered Sep 24 '22 17:09

Ta01