【发布时间】:2010-03-04 23:53:55
【问题描述】:
C#:为 TextReader 的每个 ReadLine() 解析带有一个分隔符的字符串的有效方法是什么?
我的目标是将 ListView 的代理列表加载到从 .txt 文件读取的两列(代理|端口)中。我将如何使用分隔符“:”将每个 readline() 拆分为代理和端口变量?
这就是我到目前为止所得到的,
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)
}
}
}
如果没有,有没有更有效的方法来做到这一点?
【问题讨论】: